Domanda

As far as I understand, Response.Redirect("http://stackoverflow.com"); tells the browser to initiate a request to another URL.

One of the results of this is that the browser "remembers" the redirection, and allows pressing "back."

However, I have a website where Response.Redirect disables the ability to press the browser's "Back" button, as if the browser had opened a new window. (Browsing history is not forgotten, unlike with Server.Transfer.)

The redirection used to work properly in the past, so I suspect the problem has something to do with the IIS server (IIS7).

I apologize in advance if this question should be moved to ServerFault.com.

UPDATES:

  1. Here is some code:

    protected void btnClickMe_Click(object sender, EventArgs e)
    {
        // ...
        // some server-side logic
        // ...
    
        Response.Redirect("NewPage.aspx?ProductID=" + idNum);
    }
    
  2. Regarding "disables the ability to press the browser's 'Back' button", what I meant is that the button cannot be pressed. Same as when you open a new window. The button is gray, and clicking it has absolutely no effect.

UPDATE 2:

This has been tested with IE6 and IE8.

È stato utile?

Soluzione

The problem was NOT with the Response.Redirect();.

When I was on OldPage.aspx, I entered a new URL in the address bar. Once the browser loaded the new site, it disabled the back-button.

Conclusion: There is something wrong with OldPage.aspx, not the redirection to NewPage.aspx.

I still don't know why THIS happens, but this is an entirely different question.

Altri suggerimenti

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) //check if the webpage is loaded for the first time.
        {
            ViewState["PreviousPage"] = 
        Request.UrlReferrer;//Saves the Previous page url in ViewState
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        if (ViewState["PreviousPage"] != null)  //Check if the ViewState 
                        //contains Previous page URL
        {
            Response.Redirect(ViewState["PreviousPage"].ToString());//Redirect to 
        //Previous page by retrieving the PreviousPage Url from ViewState.
        }
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top