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
<Configuration>
<System. web>
<Compilation debug = "true"/>
<Authentication mode = "Forms">
<Forms loginUrl = "login. aspx" name = ". ASPXFORMSAUTH"/>
</Authentication>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. web>
</Configuration>
Default. aspx
<HTML>
<HEAD>
<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
</Script>
</HEAD>
<BODY>
<Asp: label id = "Message" runat = "server"/>
<Br>
<Form method = "post" runat = "server">
<Asp: button id = "btnSignout" Text = "log out" runat = "server" OnClick = "btnSignout_Click"/>
</Form>
</BODY>
</HTML>
Login. aspx
<HEAD>
<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

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.

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.