2009-07-09 17:10
名字就是ASP.Login,在这个控件中有两个常用的Event, OnAuthenticate就是核实登录密码的,OnLoggedIn 就是管理登录后的事,比如Cookies,跳转到页面等等。
页面布置都放在下面的<LayoutTemplate>之中, 登录时候点击的按钮要声明,CommandName="Login" 这样按钮就和前面的事件联系起来了。此外,在OnAuthenticate的事件响应中,Argument是AuthenticateEventArgs,把这个变量的e.Authenticated属性设置为True,就可以标志用户已经进入系统的。反之,就是被拒绝。
在网页中,用this.User.Identity.IsAuthenticated来检查用户的Login状态。
asp.net login control
1. event OnAuthenticate: check login name and password, if ok, set e.Authenticated to true
protected void Login_User_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
string compoundName = ConvertUserName(this.Login_User.UserName);
Authenticated = AuthenticateUser(compoundName, this.Login_User.Password);
e.Authenticated = Authenticated;
}
2. event OnLoggedIn
check if remember me on this computer. If it is, set cookies
3.<LayoutTemplate>
customerize login control. Do whatever you like but use the specified user id and command name.
UserName
Any control that implements IEditableTextControl, including TextBox, or a custom or third-party control.
Required
Password
Any control that implements IEditableTextControl, including TextBox, or a custom or third-party control.
Required
RememberMe
CheckBox
Optional
FailureText
Any control that implements ITextControl.
Optional
Login
Any control that causes event bubbling.
Optional
4. In web.config
from the root directory
<location path="FolderName">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
from root<configure> -> System.Web
<authentication mode="Forms">
<forms name=".ASPXADBARGAINS" defaultUrl="efault.aspx" loginUrl="~/Public/LoginUser.aspx">
</forms>
</authentication>