How do I use Forms Authentication for only a portion of my site?
| Marcellino Bommezijn | |
| Beginner | |
| Language: | VB.NET |
| Platform: | Web |
To set the Forms Authentication parameters, the following must be in your web.config (for example):
<system.web>
<!-- enable Forms authentication -->
<authentication mode="Forms">
<forms name="MyAuth" loginUrl="loginpage/login.aspx" protection="All" path="/" />
</authentication>
</system.web>
Now you must define what you want to be protected. If you want to enable it for the entire site, then place the following within the <system.web> tag as well:
<authorization>
<deny users="?" />
</authorization>
However, if you want to enable it for a particular subfolder or file, then you would use <location> tags instead. The following will turn on authentication for location "store/Checkout.aspx":
<location path="store/Checkout.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
You can have as many <location> tags as you want. For more information on the <location> settings, please see the MSDN Library on Microsoft's site.
Source: MaximumASP Knowledgebase
Marcellino Bommezijn
Marcellino Bommezijn is one of the managers at UDzone.com. He is a contributor on the tutorials section.
In daily live he is a E-Business Coordinator at Geveke Motoren bv (Dutch Caterpillar Engine Dealer) and runs his own webdesign and hosting company.
(Photo: me and my son Nicky)
User Reviews
Total of 1 reviewGood primer.
Written by Afendi Hamat on August 28, 2002How about protecting individual elements on a page? For example, say certain links are shown only if you're logged in? I used to do this using cookies/session in classic ASP, just wondering if things are changed or the same in ASP.NET?






