【问题标题】:Response.Redirect() disables back-buttonResponse.Redirect() 禁用后退按钮
【发布时间】:2012-05-01 12:00:52
【问题描述】:

据我了解,Response.Redirect("http://stackoverflow.com"); 告诉浏览器向另一个 URL 发起请求。

这样做的结果之一是浏览器“记住”了重定向,并允许按“返回”。

但是,我有一个网站,其中Response.Redirect 禁用了按下浏览器“返回”按钮的功能,就好像浏览器打开了一个新窗口一样。 (与Server.Transfer 不同,不会忘记浏览历史记录。)

过去的重定向可以正常工作,所以我怀疑这个问题与 IIS 服务器(IIS7)有关。

如果这个问题应该被转移到ServerFault.com,我提前道歉。

更新:

  1. 这里有一些代码:

    protected void btnClickMe_Click(object sender, EventArgs e)
    {
        // ...
        // some server-side logic
        // ...
    
        Response.Redirect("NewPage.aspx?ProductID=" + idNum);
    }
    
  2. 关于“禁用按下浏览器的‘后退’按钮”,我的意思是无法按下该按钮。与打开新窗口时相同。按钮是灰色的,点击完全没有效果。

更新 2:

已经用 IE6 和 IE8 测试过。

【问题讨论】:

  • Response.Redirect 没有这种效果。我们可以看看一些代码吗?
  • 如果 U r 重定向到另一个站点,那么它将创建新会话
  • 请详细说明禁用按下浏览器“返回”按钮的功能 - 当您这样做时会发生什么?您到达上一页了吗?
  • @AndrewBarber 我添加了示例代码。
  • @ShadowWizard 我按要求更新了。

标签: c# asp.net redirect iis-7 post-redirect-get


【解决方案1】:

问题不在于Response.Redirect();。

当我在 OldPage.aspx 上时,我在地址栏中输入了一个新 URL。一旦浏览器加载了新站点,它就会禁用后退按钮。

结论:OldPage.aspx有问题,不是重定向到NewPage.aspx。

我仍然不知道为什么会这样,但这是一个完全不同的问题。

【讨论】:

    【解决方案2】:
    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.
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      • 2011-08-06
      相关资源
      最近更新 更多