Разрешить доступ для неаутентифицированных пользователей к определенной странице с использованием аутентификации ASP.Net Forms
Я использую аутентификацию ASP.Net Forms. Мой Web.config выглядит следующим образом.
<authentication mode="Forms">
<forms loginUrl="login.aspx"/>
</authentication>
<authorization>
<deny users="?" />
</authorization>
Поэтому в настоящее время для каждой страницы aspx требуется аутентификация.
Я хочу разрешить доступ даже к не прошедшим проверку подлинности пользователям на определенную страницу с именем special.aspx.
Как я могу это сделать?
Ответы
Ответ 1
Взгляните на пример Поддержка 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>
Ответ 2
Поместите в свой файл web.config следующее:
<location path="special.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Ответ 3
<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
Ответ 4
Разрешить всем доступ к определенной странице
Иногда вы хотите разрешить публичный доступ к какой-либо странице и хотите ограничить доступ к остальной части сайта только зарегистрированным/прошедшим проверку подлинности пользователям .i.e. не разрешать анонимный доступ. Скажем, ваш 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>