且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Asp.net成员身份-如果未通过身份验证的用户,则重定向到“登录"页面

更新时间:2021-09-30 07:31:26

首先,请确保您在应用程序根目录中的web.config具有表单身份验证设置(请注意设置登录页面):

First, make sure your web.config in the root of the application has the forms authentication setup taking note to set the login page:

<authentication mode="Forms">
     <forms name="auth" loginUrl="~/Default.aspx" timeout="20" cookieless="UseCookies" path="/" requireSSL="false" slidingExpiration="true" protection="All"/>
   </authentication>



完成此操作后,每个子文件夹都必须具有一个web.config.即/Admin/web.config.

在这种情况下,您需要说明用户的访问权限.即



Once you have done this each sub folder must have a web.config. i.e. /Admin/web.config.

In this you will need to state the access rights for the users. i.e.

<configuration>
  <system.web>
    <authorization>
      <allow roles="ADMIN" />
      <allow roles="MANAGERS" />
      <deny roles="USERS" />
      <deny roles="?" />
    </authorization>
  </system.web>
</configuration>



如果未经身份验证的用户或不正确的角色访问了该文件夹,他们将被重定向到登录页面!



If an unauthenticated user or incorrect role hits the folder they will be re-directed to the login page!