Asp.net form-based authentication prevents users from skipping logon and directly entering URLs to access the page. Unlike Session control, each page has to write code.
ASP. NET form authentication step 1: Configure web. config (web. config must be case sensitive. Generally, the key is in the camelCasing style and the value is in the PascalCasing style)
- <System. web>
- <Authentication mode ="Forms">
- <Forms name ="MainForm"LoginUrl ="Frame/Login. aspx"Protection ="All"Timeout ="60"/>
- </Authentication>
- <Authorization>
- <Deny users ="? "/> <! -- Do not write <allow users ="*"/> Otherwise, the logon page is not displayed during anonymous access -->
- </Authorization>
- </System. web>
Step 2 of ASP. NET form authentication: After the user name and password are verified in the logon button event,
- // Record Cookie
- FormsAuthentication. SetAuthCookie (loginName,False);
-
- // Redirect page
- Response. Redirect ("Frame.htm");
-
If you want to redirect to the page you want to access, that is, the page accessed before the logon page, you can use the following method to obtain the URL of the page accessed by the user at the beginning:
- String redirectionUrl = FormsAuthentication.GetRedirectUrl(loginName,false);
Then, determine whether the obtained URL is a logon page or an index page. If yes, redirectionUrl is assigned a new value to the page URL accessed during normal logon.
- if(redirectionUrl.ToLower().IndexOf("login.aspx") > 0)
- redirectionUrl = "Frame.htm";
ASP. NET form authentication completed: the final redirection page is ready.
- Response.Redirect(redirectionUrl);
- ASP. NET1.1, ASP. NET2.0, ASP. NET3.5, etc.
- ASP. NET1.1 and ASP. NET2.0: different settings of database connection strings
- ASP. NET1.1 and ASP. NET2.0 coexist
- ASP. NET1.1 implements the MasterPage function of imitation 2.0
- Experience in upgrading ASP. NET1.1 to ASP. NET2.0