Allow access for unathenticated users to specific page using ASP.Net Forms Authentication

后端 未结 4 1573
渐次进展
渐次进展 2020-11-30 07:38

I am using ASP.Net Forms Authentication. My Web.config looks like this.

    
      

        
相关标签:
4条回答
  • 2020-11-30 07:45

    Allow everyone to access a particular page

    Sometimes you want to allow public access to some page and want to restrict access to rest of the site only to logged / authenticated users .i.e. do not allow anonymous access. Say your special.aspx is in your site's root folder. In the web.config of your website's root folder you need to have following setup.

     <configuration>
        <system.web>
    
        <authentication mode="Forms"/>
    
           <authorization> <deny users="?"/>  //this will restrict anonymous user access
           </authorization>
    
       </system.web>
       <location path="special.aspx"> //path here is path to your special.aspx page 
       <system.web>
       <authorization>
        <allow users="*"/> // this will allow access to everyone to special.aspx
    
     </authorization>
     </system.web>
     </location>
     </configuration>
    
    0 讨论(0)
  • 2020-11-30 07:51
    <location path="register.aspx"> //path here is path to your register.aspx page 
    <system.web>
    
    <authorization>
    <allow users="*"/> // this will allow access to everyone to register.aspx
    </authorization>
    
    </system.web>
    </location>
    

    For more detail follow the below link

    http://weblogs.asp.net/gurusarkar/setting-authorization-rules-for-a-particular-page-or-folder-in-web-config

    0 讨论(0)
  • 2020-11-30 07:56

    Take a look at the example on MS Support

    <configuration>
        <system.web>
            <authentication mode="Forms" >
                <forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
                </forms>
            </authentication>
    <!-- This section denies access to all files in this 
    application except for those that you have not explicitly 
    specified by using another setting. -->
            <authorization>
                <deny users="?" /> 
            </authorization>
        </system.web>
    <!-- This section gives the unauthenticated 
    user access to the ThePageThatUnauthenticatedUsersCanVisit.aspx 
    page only. It is located in the same folder 
    as this configuration file. -->
            <location path="ThePageThatUnauthenticatedUsersCanVisit.aspx">
            <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
            </system.web>
            </location>
    <!-- This section gives the unauthenticated 
    user access to all of the files that are stored 
    in the TheDirectoryThatUnauthenticatedUsersCanVisit folder.  -->
            <location path="TheDirectoryThatUnauthenticatedUsersCanVisit">
            <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
            </system.web>
            </location>
    </configuration>
    
    0 讨论(0)
  • 2020-11-30 08:05

    Put the following in your web.config:

      <location path="special.aspx">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
    
    0 讨论(0)
提交回复
热议问题