且构网

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

表单身份验证重定向页面到登录页面而不是索引页面

更新时间:2022-01-25 01:07:19

请使用以下代码。这可能会有所帮助。



这里loginUrl是重定向网址,仅适用于那些需要身份验证的网页。另一方面,defaultUrl将允许用户访问普通页面。在我的代码中,根目录的admin文件夹中的.aspx页面将被要求登录,如果有人请求管理部分中的任何页面。



Kindly use the following code. It may help.

Here "loginUrl" is the redirect url that will work only for those pages which need authentication. Onthe other hand the "defaultUrl" will allow the user to visit the normal pages. Here in my code the .aspx pages inside the admin folder of the root directory will be asked to login, if anyone requests any page in admin section.

<system.web>
  <compilation debug="true" targetFramework="4.0" />
  <authentication mode="Forms">
    <forms timeout="30" loginUrl="login.aspx" defaultUrl="default.aspx" />
  </authentication>
</system.web>
<location path="admin">
  <system.web>
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>
</location>