{"id":70305,"date":"2021-09-01T04:10:05","date_gmt":"2021-09-01T08:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/allow-page-access-only-to-the-logged-in-users-net-web-applications\/"},"modified":"2021-09-01T04:10:05","modified_gmt":"2021-09-01T08:10:05","slug":"allow-page-access-only-to-the-logged-in-users-net-web-applications","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=70305","title":{"rendered":"Allow Page Access only to the Logged in Users #.Net Web Applications"},"content":{"rendered":"<p>Brought from our old site: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&amp;articleID=1349&amp;title=Allow%20Page%20Access%20only%20to%20the%20Logged%20in%20Users<\/p>\n<p>Allow Page Access only to the Logged in Users<\/p>\n<ul>\n<li> It&#8217;s common across many sites that you allow certain pages of your site only to the logged in users.<\/li>\n<li> Here, I am providing a simple way to do that in your site<\/li>\n<li> The main idea is, when users&#8217; 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<\/li>\n<li> 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.<\/li>\n<li> You will need to use this object (session variable) across your site in all restricted pages; hence, using global variables concept may help.<\/li>\n<li> 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 &#8211; if yes, go forward else redirect the user to the login page<\/li>\n<li> <a href=\"http:\/\/salearningschool.com\/samples\/asp.net\/c_sharp\/user_authentication\/LoggedInUser.txt\">The class for storing user information is as below. You can keep the class in the App_Code folder<\/a> <\/li>\n<li> <a href=\"http:\/\/salearningschool.com\/samples\/asp.net\/c_sharp\/user_authentication\/GlobalVar.txt\">Now the Global Variables Class. You can keep the class in the App_Code folder <\/a> <\/li>\n<li> <a href=\"http:\/\/salearningschool.com\/samples\/asp.net\/c_sharp\/user_authentication\/login.txt\">Now the login form (frontend) code <\/a>\n<\/li>\n<li> <a href=\"http:\/\/salearningschool.com\/samples\/asp.net\/c_sharp\/user_authentication\/login.aspx.txt\">Now the login form backend code. Check the method that checks for login credentials and  create the loggedinuser object<\/a><\/li>\n<li> <a href=\"http:\/\/salearningschool.com\/samples\/asp.net\/c_sharp\/user_authentication\/testPage.txt\">The test page that will restrict access for not logged in users<\/a>.\n<\/li>\n<\/ul>\n<p>From: http:\/\/sitestree.com\/?p=3736<br \/> Categories:.Net Web Applications<br \/>Tags:<br \/> Post Data:2016-07-16 12:02:56<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Brought from our old site: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&amp;articleID=1349&amp;title=Allow%20Page%20Access%20only%20to%20the%20Logged%20in%20Users Allow Page Access only to the Logged in Users It&#8217;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&#8217; credentials are &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=70305\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-70305","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":69896,"url":"http:\/\/bangla.sitestree.com\/?p=69896","url_meta":{"origin":70305,"position":0},"title":"Allow Page Access only to the Logged in Users #19","author":"Author-Check- Article-or-Video","date":"August 21, 2021","format":false,"excerpt":"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,\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78360,"url":"http:\/\/bangla.sitestree.com\/?p=78360","url_meta":{"origin":70305,"position":1},"title":"Data Types  in Application and Session State Variables with examples","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"Here's a clear and blog\/Facebook-ready answer to: \u2753 What Type of Data Can You Store in Application State and Session State Variables in ASP.NET? In ASP.NET, both Application State and Session State are used to store data on the server side \u2014 but they serve different purposes and scopes. Below\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69268,"url":"http:\/\/bangla.sitestree.com\/?p=69268","url_meta":{"origin":70305,"position":2},"title":"SQL Server : Backups #38","author":"Author-Check- Article-or-Video","date":"August 16, 2021","format":false,"excerpt":"Why are backups needed? To protect accidental data loss. Still, if you use highly available and fault-tolerant systems like SAN, and RAID, you may need to backup your database regularly. These fault tolerant systems can not provide accidental data delete by users, accidental data corruption from software and hardware failure.\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78352,"url":"http:\/\/bangla.sitestree.com\/?p=78352","url_meta":{"origin":70305,"position":3},"title":"State in .Net (C#, ASP.Net)","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"From AI: Certainly! Here's a copyright-free, blog and Facebook-ready version of the explanation on State Management in C#\/.NET. You can copy, paste, and share this freely on your blog, website, or social media. No attribution is required (but you're welcome to add your name or page if you like). \ud83c\udf10\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78358,"url":"http:\/\/bangla.sitestree.com\/?p=78358","url_meta":{"origin":70305,"position":4},"title":"Application State Variables in C#.net","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"Here\u2019s a clear, copyright-free explanation of Application State Variables in C#.NET, ideal for blogs, Facebook pages, or classroom notes. \ud83c\udf10 Application State Variables in C#\/.NET Application State in ASP.NET is a way to store global data that is shared by all users across the entire web application. It is commonly\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":62821,"url":"http:\/\/bangla.sitestree.com\/?p=62821","url_meta":{"origin":70305,"position":5},"title":"PHP Security &#8211; Guidelines #PHP","author":"Author-Check- Article-or-Video","date":"May 21, 2021","format":false,"excerpt":"This actually is a pretty old short note and was brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1357&title=PHP%20Security%20-%20Guidelines Do not store sensitive information in Cookies Instead of cookies, store sensitive information in Sessions Sessions can also be hacked though safer than cookies PHP session id is pretty random; so in general this is not a\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70305"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70305\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70305"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}