Forms Authentication Ignoring Default Document
This was my solution:
In Global.asax
, method: Application_BeginRequest
, place the following:
if (Request.AppRelativeCurrentExecutionFilePath == "~/") HttpContext.Current.RewritePath("HomePage.aspx");
Nice and simple, and you have a chance to build logic around what home page you want to use if your website uses multiple home pages based on configuration variables.
Dmitry.Alk
I was seeing this same problem when attempting to hit the root path and I tried everything previously mentioned. It seems Asp.net 4.0 adds two ExtensionlessUrl modules to applicationhost.config for IIS 7. You can remove these modules by adding the following to your web.config
<system.webServer> <handlers> <remove name="ExtensionlessUrl-Integrated-4.0"/> <remove name=" ExtensionlessUrl-ISAPI-4.0_32bit "/> </handlers></system.webServer>
Additional Information
What I ended up doing to fix this is writing a few lines of code in my login page to check for a Request.QueryString["ReturnUrl"] of "/". If it found that, then it redirected to default.aspx.
I couldn't find ANY way to make forms authentication not intercept calls without a page specified (e.g. www.mysite.com). :( I even tried .NET 4 URL Routing and that didn't prevent Forms Authentication from hijacking the request either.
Below is the code I used in login.aspx:
protected void Page_Load(object sender, EventArgs e){ if (!(IsPostBack || IsAsync)) { string returnUrl = Request.QueryString["ReturnUrl"]; if (returnUrl != null) if (returnUrl == "/") Response.Redirect("default.aspx"); }}