About Forms authentication in asp.net

Source: Internet
Author: User
Tags ticket

Each web developer is more or less exposed to authentication, and the most likely contact is Windows authentication and forms authentication, and here's an overview of forms authentication in the past.
Before I start, I'll create a new Web project for testing, and here are a few of the main directories:
Admin directory: Admin directory--default.aspx Administrator Directory page User directory: Normal user directory--default.aspx normal user Directory page root: root--default.axpx root directory default page--lo Gin.aspx the login page under the root directory--web.config the configuration file under the root directory--global.asax the global control file under the root directory (added manually after VS2005)
Later we will describe a complete validation process for Web.config configuration, login page authentication, and user authentication in Global.asax.
         One: Web.config setting <!--enabling forms authentication--> <authentication mode= "Forms" > < Forms Name= "Beginningweb2008.apsxauth" loginurl= "Login.aspx" path= "/" protection= "All"/> </authentication> <!--deny all anonymous users access to--> <authorization> <deny users= "?" /> <allow users= "*"/> </authorization> <!--settings Login.aspx can access anonymous--> <location path= " Default.aspx "> <system.web> <authorization> <allow users=" * "/> </authorization> </ System.web> </location> 

        //two: Authentication protected void Button1_Click (object sender, EventArgs e) {if (txtusername.te XT!= "" && txtpassword.text!= "") {string user_name = txtUsername.Text; Formsauthentication.initialize (); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (1, user_name, DateTime.Now, DateTime.Now.AddMinutes ( 5), True, "User defined data Here", Formsauthentication.formscookiepath); String encticket = Formsauthentication.encrypt (ticket); HttpCookie cookies = new HttpCookie (Formsauthentication.formscookiename, Encticket); RESPONSE.COOKIES.ADD (cookie); Response.Redirect (Formsauthentication.getredirecturl (user_name, true)); }} 

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.