Response.Redirect - the problem of sending a redirect with a hash if the destination URL with a hash was on the current page

I am using ASP.NET Webforms C # 3.5 and using Response.Redirect to redirect the page after the event is fired.

If I send a request, the first request will work fine. I am currently using Response.Redirect. I tried using Server.Transfer and passed True and False as the second parameter to the Redirect function, and also tried to disable SmartNavigation.

IF I click the Submit button, the page does what it should have, and the anchor forces the page to the right place. If I then send the request again, the same URL is returned, and the browser will do nothing but sit and hang. If I remove the hashed portion from my URL, the redirect works fine.

The problem only occurs if the request was redirected to the current URL with the anchor, and a new redirect occurs with the anchor (hash symbol)

Response.Redirect(/Script.aspx?param1=something&param2=something#anchor);

I also tried this:

Response.Redirect(/Script.aspx?param1=something¶m2=something&#anchor);

In any case, removing the anchor fixes the problem.

Chrome Firefox. Firebug , , , , , . , , \- .

+3
1

Response.Redirect.

Response.Headers.Add("Location", "/Script.aspx?param1=something#anchor");
Response.Status = "301 Moved Permanently"; //or whatever status code you want to deliver, 302 or 307 are standard for Response.Redirect(...)

javascript :

//page
Response.Redirect("/Script.aspx?param1=something&anchor=anchor");

//script.aspx
void Page_Init(object sender, EventArgs e)
{
    ClientScript.RegisterClientScriptBlock(typeof(string), "anchor", "<script type=\"text/javascript\">location.href = location.href + '#" + Request["anchor"] + "';</script>");
}
+7

All Articles