1
votes

After authentication, asp.net redirects my users to .../myapp/default.aspx instead of .../myapp/

Is there some way of fixing this? I think it's a little ugly not to mention redundant to contain the extra default.aspx on the url.

I've tried putting the following code in my default.aspx.cs page_load function, but it results in a redirect loop because it cannot distinguish whether the user is accessing myapp/ or myapp/default.aspx:

if (Request.RawUrl.ToLower().EndsWith("/default.aspx"))
  Response.Redirect("./");

Thanks!

6
I've also tried adding the following to the forms section in web.config: defaultUrl="./" - Chris
The web.config setting should be defaultUrl="~/" (The tilde signifies "this app's virtual path"). - devstuff
Did the above work? If so, let @devstuff know so that he can post this as a solution below and get some points :) - Tommy
Rather than trying to handle this yourself in code, have you tried just leaving out the defaultURL completely from your web.config? <forms loginUrl="login.aspx" timeout="20" /> - Tommy

6 Answers

6
votes

If you are using a login control, decide yourself how the redirect will happen. Use the login control's event (I think it is Authenticate) and:

if (Request.QueryString["ReturnUrl"] != null)  
{  
    FormsAuthentication.RedirectFromLoginPage("someuserid", false);  
}  
else  
{  
    FormsAuthentication.SetAuthCookie("someuserid", false);  
    Response.Redirect("~/SomePage.aspx");  
} 
1
votes

The easiest way to fix this is just to remove the defaultUrl attribute from the web.config

<authentication mode="Forms">
    <forms ... defaultUrl="default.aspx" ... />
</authentication>

When you visit www.yourwebsite.com/myapp, the return url will be "/myapp/", and after login, it will redirect back to "/myapp/". If you use the defaultUrl like above, it will redirect to "/myapp/default.aspx". Actually, I experimented with this on the root of the site, but I would think it works the same for subdirectories.

0
votes

You will need to look at the default page that is set up in IIS.

0
votes

It's not a redundant redirect.

Why? Because when you hit / on a web server, the webserver redirects you to /default.aspx anyway. You're just letting IIS do it instead of the authentication mechanism.

-Oisin

0
votes

Actually there is no such file like "./" to process for a web server. There MUST be a default file which will be served to client. Because nobody wants to type "blabla.com/index.aspx" instead of "blabla.com". Your problem is choosing which page to be called as default.

In IIS, right-click to your web site and go for properties.

There is a tab, which contains "Default Page" order. There must be a couple of web pages like "index.htm, default.aspx, etc". Change these filenames' order. The page you want to be called must be at the top.

PS: YOUR Login page and Logged page are same page! So it will be called redundantly!

0
votes

I was having the same issue. My login page was default.aspx and when you hit the application, the redirect url was set to /MyApp/.

I think the end result is that I had to rename my login page to soemthing else (login.aspx)