how to redirect to login page if user directly entres URL in browser using ASP.NET

asp.net c# entity-framework-6

Question

I am working on asp.net entity framework. I want to access the pages only through login and not directly by entering the URL of the page. If user enters the URL of the page and tries to access it then he should be redirected to Login Page. How can I do that? User are supposed to login with username and password from DB. I am new to ASP.NET

1
2
4/19/2016 1:38:34 PM

Popular Answer

The functionality you are looking for can be achieved by adding the following authentication/authorization sections to the ASP.NET Web.config file like shown in the following example:

<system.web>
  <authentication mode="Forms">
    <forms name="SomeName" 
           loginUrl="Login.aspx" 
           protection="All" 
           path="/">
    </forms>
  </authentication>
  <authorization>
    <deny users="?" />
  </authorization>
</system.web>

It essentially denies all access for unauthenticated Users: if such unauthenticated User tries to access any page at your website, then he/she will be redirected to the Login.aspx page ( details at MSDN https://msdn.microsoft.com/en-us/library/wce3kxhd.aspx, https://msdn.microsoft.com/en-us/library/xdt4thhy.aspx).

Hope this will help.

6
4/19/2016 1:49:25 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow