A simple ASP. NET Forms authentication

Source: Internet
Author: User
When you access the default homepage default. when aspx is used, login is automatically redirected. log on to the aspx page. Enter your username and password and click "log on" to return to the home page and display the username of the current logon.
Web. config
<System. web>
<Compilation debug = "true"/>
<Authentication mode = "Forms">
<Forms loginUrl = "login. aspx" name = ". ASPXFORMSAUTH"/>
<Deny users = "? "/>
</System. web>
Default. aspx
<TITLE> homepage </TITLE>
<Script language = "VB" runat = "server">
Sub Page_Load (Sender As Object, e As EventArgs)
Message. Text = String. Format ("Hello, {0}", Context. User. Identity. Name)
End Sub
Sub btnSignout_Click (Sender as Object, E as EventArgs)
FormsAuthentication. SignOut ()
Response. Redirect ("login. aspx ")
End sub
<Asp: label id = "Message" runat = "server"/>
<Form method = "post" runat = "server">
<Asp: button id = "btnSignout" Text = "log out" runat = "server" OnClick = "btnSignout_Click"/>
Login. aspx
<TITLE> homepage </TITLE>
<Script lanugage = "c #" runat = "server">
Private void Page_Load (object sender, EventArgs e)
If (Request. IsAuthenticated)
Response. Redirect ("default. aspx ");
Void btnLogin_Click (Object sender, EventArgs e)
If (txtUsername. Text! = Null & txtUsername. Text! = String. Empty & txtPassword. Text! = Null & txtPassword. Text! = String. Empty)
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.