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)); }}