Saturday, February 18, 2012

Giving anonymous access to a page and folder using form authentication


One of my friend has the problem using for accessing the page and folder using the form authentication. I thought I should put this solution in the blog. Whenever we use the Form Authentication for the authentication we use the following configuration in the web.cofig file


 <authorization>
      <deny users="?"></deny>
    </authorization>
    <authentication mode="Forms">
      <forms name="MyAuthAsp" defaultUrl="default.aspx" loginUrl="login.aspx" cookieless="AutoDetect" path="/" protection="All" timeout="20"/>
  </authentication>
 

here  <authorization>  section restrictes all the anonomous user to access the other pages of the site. Now the problem is that I need to access some pages i.e. faq.aspx, contact.aspx, career.aspx which are in the root of the site or css and javascript files then I can not go directectly to those pages. To overcome this problem you just need to add the following section in the web.config file


<location path="Default.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
 

Now the Default.aspx page will be accessable by the anonomous users withoug login. If you want to access more pages then add that section with the differenct path.


<location path="style.css">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
 

If you have to access a folder or all the pages of a particula folder then you can specify the folder path here.


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

No comments:

Post a Comment