我试图使自己的登录功能,而无需使用会员提供的,但我登录使用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