safi
safi

Reputation: 3766

un authenticated user must not access pages by typing in URl

in my web-application, an authenticated user can access this URL localhost/mydata.aspx, but an un-authenticated user type this URL he can also access this page. so how to prevent unauthorized user from access this page and if they does redirecting them to login.aspx

Upvotes: 0

Views: 2994

Answers (1)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Add the following in your web.config file under the configuration section:

<system.web>
  <authorization>
    <deny users="?"/>   
      </authorization>
</system.web>

And if you want to restrict access to a particular folder:

<location path="FolderPath">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>

This will allow access to unauthenticate a user:

<location path="LoginPage.Aspx">
   <system.web>
  <authorization>
    <allow users="*"/>  
      </authorization>
</system.web>
</location>

Upvotes: 3

Related Questions