Brought from our old site: http://salearningschool.com/displayArticle.php?table=Articles&articleID=1349&title=Allow%20Page%20Access%20only%20to%20the%20Logged%20in%20Users
Allow Page Access only to the Logged in Users
- It's common across many sites that you allow certain pages of your site only to the logged in users.
- Here, I am providing a simple way to do that in your site
- The main idea is, when users' credentials are verified, we store the information in the session object. Later, if a restricted page is being accessed, we check if the user is a verified/(logged in) user, if so we allow him access otherwise not
- You can use individual session variables to store some information about the user and logged in status. However, that may not be a great way. Better, to use an object to store user information and login status information. Then throw that object to the session variable.
- You will need to use this object (session variable) across your site in all restricted pages; hence, using global variables concept may help.
- Here, I will present code that will show you 1. a class to store user information 2. global variables class implementing the method to check if any user is logged in [from anywhere in your application] 3. a login form that will create a user object to store user information upon successful login and throw that object in session 4. a test restricted page that will check if any user is logged - if yes, go forward else redirect the user to the login page
- The class for storing user information is as below. You can keep the class in the App_Code folder
- Now the Global Variables Class. You can keep the class in the App_Code folder
- Now the login form (frontend) code
- Now the login form backend code. Check the method that checks for login credentials and create the loggedinuser object
- The test page that will restrict access for not logged in users.
From: http://sitestree.com/?p=3736
Categories:.Net Web Applications
Tags:
Post Data:2016-07-16 12:02:56
Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a>
In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
<a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>