How to implement Forms authentication of a directory

xiaoxiao2021-03-06  41

Some time to study the problem of login verification of the background, I heard that Forms authentication is convenient, so it is found that the information on the Internet is not full (or not suitable for beginners), there is a lot of problems, now I put it My code is published, I hope to give you some help. My background file is all in the admin directory, the login port of the background is admin_login.aspx, and the functionality to be implemented is: Can't directly access the Admin Directory In addition to admin_login.aspx (Ie the files outside the login port), but the front desk file, such as Default.aspx, etc., should not be affected by Forms verification, that is, even if there is no login, access Default.aspx, can not go to Admin_login.aspx Let's talk about the implementation process: in the web.config file, set to Forms authentication: and then join: Otherwise, no matter which file is accessed, it will go to the login port. After adding the above code, only when the file in the admin directory may go to Admin_login.aspx, the above is the setting in the web.config file, the next is the code of the background login button: // Check the login Whether the username and password are correct, I use the method you check from the database, you can use other methods, you don't say .IF (OpenData.Checkuser (strsql, "toempire_userinfo)) {// Save the user name Session ["Loginuser"] = strloginuser; // This sentence is the key, strloginuser is used in the login box Account name. False is not permanent record. Formsauthentication.redirectFromLoginPage (Strloginuser, False);

Response.Redirect ("admin_index.aspx");} The above is the implementation process of Forms authentication, I hope to be useful to you. If you have any questions, please leave a message here, I will reply.

转载请注明原文地址:https://www.9cbs.com/read-54420.html

New Post(0)