Response.Redirect not always redirecting

2019-07-07 05:44发布

We have a simple Response.Redirect on a page that is working inconsistently (IIS 6.0). Most of the time it redirects correctly, but we're getting some users that are complaining that instead of redirecting, they are getting the "302 Object moved to here" page. The page displays the header information with the correct location. If you click "here," it redirects to the correct page.

Any ideas why it would display the 302 message sporadically?

3条回答
倾城 Initia
2楼-- · 2019-07-07 06:10

You could try to manually set the status code of the response to 301. Here is some borrowed code that should help you out:

Response.StatusCode = 301; 
Response.StatusDescription = "Moved Permanently";
Response.RedirectLocation = "RedirectionPage.aspx";
Response.Flush();

You could also use as a last-ditch effort Server.Transfer() or output a simple script that sets the window's location to the new url.

Page.ClientScript.RegisterStartupScript(Page.GetType
"RedirectScript", "window.location.href='RedirectionPage.aspx'", true);

Although I wonder how well their browsers will do with javascript if they're not respecting the original redirection.

Do you have any information on the browsers these people are using?

查看更多
仙女界的扛把子
3楼-- · 2019-07-07 06:22

This can occur when the Location header is missing.

查看更多
Summer. ? 凉城
4楼-- · 2019-07-07 06:29

302 IS the code response.redirect returns. I also saw a note to do a client-side

window.location = 'url'

but it does sound like a browser setting.

查看更多
登录 后发表回答