ASP.net的Login控制項(zhuan)

來源:互聯網
上載者:User

 

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=&quotefault.aspx" loginUrl="~/Public/LoginUser.aspx">
</forms>
</authentication>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.