Разрешить доступ пользователям, не прошедшим проверку подлинности, к определенной странице с использованием проверки подлинности на основе форм ASP.Net - PullRequest
42 голосов
/ 02 сентября 2010

Я использую ASP.Net Forms Authentication.Мой Web.config выглядит следующим образом.

    <authentication mode="Forms">
      <forms loginUrl="login.aspx"/>
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>

Так что в настоящее время каждая страница aspx требует проверки подлинности.

Я хочу разрешить доступ даже не прошедшим проверку подлинности пользователям к определенной странице с именем special.aspx.Как я могу это сделать?

Ответы [ 4 ]

53 голосов
/ 02 сентября 2010

Посмотрите на пример по Поддержка MS

<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>
17 голосов
/ 02 сентября 2010

Добавьте в ваш web.config следующее:

  <location path="special.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
2 голосов
/ 29 июня 2016

Разрешить всем доступ к определенной странице

Иногда вы хотите разрешить публичный доступ к какой-либо странице и ограничить доступ к остальной части сайта только зарегистрированным / аутентифицированным пользователям.не разрешать анонимный доступСкажите, что ваш special.aspx находится в корневой папке вашего сайта.В файле web.config корневой папки вашего сайта вам необходимо выполнить следующие настройки.

 <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>
2 голосов
/ 02 февраля 2016
<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>

Для получения более подробной информации перейдите по ссылке ниже

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...