简体   繁体   中英

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?

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM