how to secure a single aspx page in asp.net websit

2019-08-21 12:48发布

问题:

I have multiple aspx pages in my web site but i want to secure only one page.I used the asp.net membership and role manager but it require user name and password for all pages but i want to secure only a single page.please any one can help me how can i do this in vb.net with asp.net .I have used the following code in web.config but it applies on all pages which i dnt want

<authorization>
   <allow users="sml" />
   <deny users="?" />
   <deny roles="users" />
  </authorization>
  <roleManager enabled="true" />
   <authentication mode="Forms">
     <forms loginUrl="Login.aspx"  timeout="9820"  defaultUrl="Food.aspx"  cookieless="AutoDetect" >
     </forms >
   </authentication >

回答1:

 <location path="ProtectedPage.aspx">
    <system.web>
      <authorization>
        <allow roles="sml" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>


回答2:

you can use URL Authorization for that

<location path="page.aspx" />
  <authorization>
    <allow users="Bob" />
    <deny users="*" />
  </authorization>
</location>

check http://msdn.microsoft.com/en-us/library/ff649337.aspx



回答3:

Try to modify your web.config. as mentioned below.

<secureWebPages>
<files>
    <add path="Default.aspx" secure="Insecure" />

    <add path="Admin/MoreAdminStuff.aspx" secure="Ignore" />

    <add path="Legal/Copyright.aspx" secure="Ignore" />

    <add path="Lib/PopupCalendar.aspx" secure="Ignore" />

</files>
<directories>
    <add path="/" recurse="False" />

    <add path="Admin" />

    <add path="Admin/Info" secure="Insecure" />
    <add path="Members/Secure" recurse="True" />

</directories>

Refer http://www.codeproject.com/Articles/7206/Switching-Between-HTTP-and-HTTPS-Automatically-Ver for more details.