我如何确保授权我的网站根页?

时间:2014-06-24 13:21:48

标签: c# asp.net webforms forms-authentication

我有一个在IIS 7上使用.Net 4.0进行ASP.NET表单身份验证的网站。我已经使用第三方单点登录提供程序(jasig CAS)保护了该站点,并且一切正常。

IIS中的默认文档列表在最顶部有Default.aspx。

该网站的默认页面是Default.aspx,它通过我的web.config中的以下片段向公众开放,当我直接导航到该页面时,这也会按预期工作。

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

我遇到的问题是,当我浏览网站的根目录时,即 www.mydomain.com 而不是 www.mydomain.com/default.aspx 我被重定向到表单身份验证页面。

当然这是同一页面,并且受相同的授权规则约束?

我坚持这个,不知道在哪里转。

2 个答案:

答案 0 :(得分:2)

Stack Overflow中有类似的问题:

Allowing anonymous access to default page

在Global.asax中,将以下代码放在Application_BeginRequest方法中:

if (Request.AppRelativeCurrentExecutionFilePath == "~/")
    HttpContext.Current.RewritePath("default.aspx");

答案 1 :(得分:0)

我最终使用了这段代码(与上面相同),但它必须进入CasAuthenticationModule中的OnBeginRequest方法

if (Request.AppRelativeCurrentExecutionFilePath == "~/")
    HttpContext.Current.RewritePath("default.aspx");