Nil Pun
Nil Pun

Reputation: 17383

IIS 7 ASP.NET 4.0 Ignoring Default Document

We have a ASP.NET 4.0 web application upgraded from 3.5. Unfortunately when the user tries to access the URL via http://xxx.abc.com/, the user gets /login.aspx?ReturnUrl=%2f.

I understand that this seems to be a behaviour on .NET 4.0 and IIS7. This is causing an issue with load balancer as it returns 302 status code. Some reason the load balancer has been configured to look for http 200 status code.

Is there any way we can fix the ASP.NET 4.0 behaviour so that when user clicks on http://xxx.abc.com/, show the login.aspx without redirection?

I tried this below but did not work:

<system.webServer>
    <defaultDocument>
      <files>
        <add value="Login.aspx" />
      </files>
    </defaultDocument>
</system.webServer>

Thanks.

Upvotes: 3

Views: 2184

Answers (1)

McGarnagle
McGarnagle

Reputation: 102793

It's not a behavior of .NET 4 / IIS 7, it's a behavior of forms authentication. It seems that the Authentication module gets run first, and triggers the redirect before the Default Document module gets its chance. Here's what I would suggest as a workaround:

  • set <allow users="?" /> on the root of your website by using the location tag.
  • if the above is not possible or practical, use the URL Rewrite module instead of relying on Default Document.

I used this rewrite rule to get login.aspx returned from the root URL with a 200 status code :

<rewrite>
  <rules>
    <rule name="RewriteURL1" stopProcessing="true">
      <match url="" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Rewrite" url="login.aspx" />
    </rule>
  </rules>
</rewrite>

Upvotes: 4

Related Questions