Pages

Sunday, May 17, 2009

Exclude Pages from ASP.NET Authentication


Recently i discovered an interesting feature of asp.net where we can exclude page(s) from asp.net authentication. Usually once we have asp.net authentication setup, our requests to different pages must be authenticated. But at times we may require to exclude some of the page(s) from this restriction. This can be easily done by adding a <location> section in the web.config file. The <location> tag goes under the <configuration> section and can be defined as following:


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


This tag can also be applied to page in a specific folder as following:

<location path="myfolder/excludepage.aspx">

We can have several <location> tags defined for seperate pages in a web.config file. However, if you have many pages to be excluded, a better approach is to move all the pages under one folder and specify this folder in the <location> tag as following:

<location path="myfolder">

Do keep in mind that if excluded pages reference a css, image etc file, those too must be excluded in order work properly.

Hope this post has been helpful. Stay tuned for more...

No comments:

Post a Comment