我試圖使自己的登錄功能,而無需使用會員提供的,但我登錄使用System.Web.UI.WebControls.Login
控制和設置使用FormsAuthentication.SetAuthCookie(username, rememberMe);
爲什麼必須指定成員資格提供
身份驗證Cookie後,我得到了以下錯誤消息
必須指定默認成員資格提供程序。
我想知道爲什麼必須指定它?
我試圖使自己的登錄功能,而無需使用會員提供的,但我登錄使用System.Web.UI.WebControls.Login
控制和設置使用FormsAuthentication.SetAuthCookie(username, rememberMe);
爲什麼必須指定成員資格提供
身份驗證Cookie後,我得到了以下錯誤消息
必須指定默認成員資格提供程序。
我想知道爲什麼必須指定它?
我可以在沒有自己的登錄表單的情況下使用它。我剛剛從webconfig中刪除了成員資格提供程序部分。
您必須在web.config中添加一個部分,告訴它在哪裏尋找您的會員名單。這將是包含用戶的數據庫,活動目錄組等。否則,您的應用程序如何知道在哪裏對用戶進行身份驗證?
查看MSDN's Introduction to Membership瞭解更多信息。
System.Web.UI.WebControls.Login
與會員提供商緊密耦合。如果您想在沒有成員資格提供者的情況下登錄,則只需使用文本框和按鈕創建自己的登錄表單。
我知道這是舊的,但我只是無意中發現了這個問題,因爲我已經做了這個想分享我的解決方案,以防其他人應該有需要。
該捕獲是你需要處理控件的OnAuthenticate
事件。在最簡單的形式,你會有這樣的ASPX:
<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
</asp:Login>
這在後面的代碼:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) {
e.Authenticated = FormsAuthentication.Authenticate(Login1.UserName, Login1.Password);
}
這在web.config中:
<membership>
<providers>
<clear/>
</providers>
</membership>
<authorization>
<allow users="?"/>
</authorization>
<authentication mode="Forms">
<forms cookieless="UseCookies" loginUrl="~/Login.aspx" path="/" protection="None" name="user_login_cookie">
<credentials passwordFormat="Clear">
<user name="user" password="password_in_clear!"/>
</credentials>
</forms>
</authentication>
這將讓您在web.config中使用硬編碼用戶的簡單登錄表單。適用於原型和演示,請勿將用戶帳戶放入web.configs中以供現場使用!
謝謝,我可以使用它,而無需使自己的登錄表單。我剛剛從webconfig中刪除了成員資格提供程序部分。 – Homam 2011-02-28 14:47:15