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>