views:

47

answers:

5

Hi,

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!

A: 

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

Jerod Houghtelling
I am sure it is fine. In IIS, if you do not specify a page, it will try to serve up your default pages in order of preference. If you do specify a page, default or not, it will still show that page in the URL. This is why he is seeing this behavior.
Tommy
Ah yes, you are correct. I misinterperted the question.
Jerod Houghtelling
A: 

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!

algorian
I think you're misunderstanding me: my app is set up correctly so that http://blah/myapp/ goes to my default.aspx. I just want authentication to not put the /default.aspx on redundantly when it does its redirects.
Chris
Is that just because of not showing the file name "default.aspx" ?Because your code is nothing to do with the authentication. You simply say if the URL ends with "default.aspx", then go to "./" which redirects you to same location.
algorian
@Algorian - When he first goes to his site, it does not show the default.aspx in the URL, which is good - default pages are setup correctly. However, the login.aspx page has a querystring parameter of ?ReturnURL=default.aspx. Once a user logs in, they are returned to the home page, but default.aspx is in the URL because of this. This is what the poster is looking to avoid.
Tommy
Ok, it is all about avoiding dafault.aspx in URL. Then he should try @devstuff's advice!
algorian
A: 

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

x0n
I'd prefer it this way, for the sake of SEO and cleaner URL's.
Chris
SEO? This is not an entry point for search engines - it's a login page.
x0n
+1  A: 

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");  
} 
CRice
A: 

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.

Kasey Speakman
Does this *really* work? If so, that sounds too good to be true.
Chris
I've confirmed that it works on root paths, but it's a catch-22 on subdirectories. If you have a default.aspx in the sub-directory (and assuming it's setup in IIS as a default page), it changes the ReturnUrl to "/myapp/default.aspx?". If you DON'T have a default.aspx, the ReturnUrl will be "/myapp/" but that will result in a directory listing page after login. :/
Kasey Speakman