jdaval
jdaval

Reputation: 640

Problems with response.redirect

I have a very basic test page, with a button and on the button click a call to

Response.Redirect("b.aspx") This works fine when the page is loaded as http://myhost/index.aspx. However when the same page loads via http://myhost/, the redirect doesn't work (the same page just reloads like a normal postback).

The server is IIS7 running ASP.NET4.

I have also tried Response.Redirect("~/b.aspx")? And still no soup?

Upvotes: 0

Views: 2519

Answers (3)

Ňuf
Ňuf

Reputation: 6217

I'm not able to reproduce your behavior. I have written two aspx pages that you described and when i click button on index.aspx page, I'm redirected to b.aspx no matter if I access page as http://localhost/index.aspx or just http://localhost/ (after I set index.aspx as default document in IIS). So it must be some kind of mistake or problem with IIS configuration.

I would suggest to ensure in debugger, that Response.Redirect() is really executed and use tool such as Fiddler to inspect response headers.

Upvotes: 0

Amaranth
Amaranth

Reputation: 2511

You might want to try to set a default page. In visual studio, go in the property pages of your project, in start options, select the start action to a specific page to to your index.aspx. This way, when you access with http://myhost/, it will go to http://myhost/index.aspx.

Upvotes: 0

Servy
Servy

Reputation: 203812

Try Response.Redirect("...", true);

It won't let the rest of the code run on the page, and the rest of the code might be a server transfer from the root to the welcome page, which is messing you up.

Upvotes: 1

Related Questions