0

我正在开发一个 ASP.NET Web 窗体应用程序,并且我Account在根目录下有一个文件夹。其中主要包含三个 ASPX 页面:Login.aspx, ChangePassword.aspx, ForgotPassword.aspx.

我已经使用自定义成员资格提供程序配置了表单身份验证。

网络配置

<authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" slidingExpiration="true" timeout="2880" path="/" protection="All" />
</authentication>

<membership defaultProvider="CustomMembershipProvider">
  <providers>
    <clear/>

    <add name="CustomMembershipProvider" 
         type="App_Code.CustomMembershipProvider, Portal.Web" 
         connectionStringName="PortalConnectionString"
         applicationName="/" />
  </providers>
</membership>

如果我尝试访问Account文件夹中的页面而不是Login.aspx我一直重定向到的页面,Login.aspx并且我目前正在避免其他两个页面的表单身份验证,如下所示,

  <location path="Account/ChangePassword.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

  <location path="Account/ForgotPassword.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

我可以将它们组合起来,而不是像上面那样指定单个页面吗?我尝试Accountpath属性中指定文件夹名称,但这不起作用。

接下来是我Dashboard.aspx在根目录中调用了另一个页面,每当我直接访问它时,我以为我会被重定向到该Account/Login.aspx页面,但它没有发生,为什么?

4

1 回答 1

1

您绝对可以将文件夹指定为路径属性 - 如果您保留它,请尝试删除尾随 /,例如

 <location path="account">
    <system.web>
      <authorization>
        <deny users="?" />
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

但是,因为您想保护帐户文件夹中的其他页面,您需要覆盖专门为匿名用户提供的页面,例如 Login.aspx 和 ResetPassword.aspx。您不能合并多个文件条目。

至于 Dashboard.aspx 重定向的原因,您未在此处发布的配置中肯定还有其他原因导致了这种情况。

于 2012-12-11T12:35:37.263 回答