Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to protect just the Admin page of my site but my code protects all pages.
What changes should I make to my code?

What I have tried:

system.web>
      <authentication mode="Forms">
        <forms name="SavingsPlan" defaultUrl="admin.aspx" loginUrl="Login.aspx" >
          <credentials passwordFormat="SHA1">
            <user name="Admin"
                  password="07B7F3EE06F278DB966BE960E7CBBD103DF30CA6"/>
            <user name="User"
                  password="BA56E5E0366D003E98EA1C7F04ABF8FCB3753889"/>
          </credentials>
        
        </forms>
        
      </authentication>
   <authorization>
     <allow users="Admin"/>
     <deny users="?"/>
   </authorization>
Posted
Updated 3-Oct-17 6:51am

1 solution

To specify configuration which only applies to a specific file, use the <location> element:
location Element (ASP.NET Settings Schema)[^]
XML
<system.web>
    <authentication mode="Forms">
        ...
    </authentication>
</system.web>

<location path="admin.aspx">
    <system.web>
        <authorization>
            <allow users="Admin"/>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900