Tuesday, February 22, 2011

Common mistake in ASP.NET Forms Authentication

We are all used to this now...


<configuration>

    <system.web>

    <authentication mode="Forms">

    </authentication>

    </system.web>

</configuration>


In ASP.NET Forms authentication, you can allow access to particular users or deny them using the allow and deny tags. Likewise, you can allow or deny access to particular roles.
E.g. to allow access to a page, say Customer, you will do


<location path="Customer">

  <system.web>

        <authorization>

            <allow roles="Customers"/> //Allow users in Customers role

        <deny users="*"/> // Deny rest of all users

    </authorization>

   </system.web>

</location>



Common Mistake is to place 

<deny../> before <allow ../>


This web config below will not allow users even if they are in Customers role


<location path="Customer">

  <system.web>

        <authorization>

            <deny users="*"/> // Deny rest of all users

            <allow roles="Customers"/> //Allow users in Customers role       

    </authorization>

   </system.web>

</location>

2 comments:

Julius.Bichage said...

Some interesting stuff on Forms Authentication here:
http://aspalliance.com/2045_Creating_a_Login_Overlay.all

Naviya Nair said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training in India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai