Chrome / Safari后退按钮问题

时间:2012-08-03 12:24:15

标签: c# asp.net

我正在申请我们可能有5或6个步骤。 在第一步中,我将选择我需要的报告并保存并继续..这将让我迈出第二步......就像这样...... 我的问题是根据功能,当我点击浏览器后退按钮我需要转到上一页。 再次当我第二次按它必须转到我的主页时, 但它将我重定向到上一页。 它适用于除chrome和safari之外的所有浏览器。 我正在插入我的代码供参考..请帮我解决这个问题..

protected void Page_Load(object sender, EventArgs e)
{

    DisableHistory();
    lnkBackBrowse.Style["visibility"] = "hidden";
    if (Session["UserId"] != null)
    {
        if (Convert.ToInt32(Session["UserId"].ToString()) == 0)
        {
            TopNavigationMenu.Style["visibility"] = "hidden";
            NavigationMenu.Style["visibility"] = "hidden";

            if (!Request.Url.ToString().Contains("Home") && !Request.Url.ToString().Contains("SaveandLogout"))
                Response.Redirect("Home.aspx");
        }
        else
        {
            TopNavigationMenu.Items[0].Text = "Welcome :" + Session["UserName"].ToString();
            TopNavigationMenu.Style["visibility"] = "visible";
            NavigationMenu.Style["visibility"] = "visible";

            if (Session["FirstTimeLogged"] != null && Convert.ToBoolean(Session["FirstTimeLogged"]) == true)
            {
                TopNavigationMenu.Enabled = false;
                NavigationMenu.Enabled = false;

                if (!Request.Url.ToString().Contains("MyAccount"))
                    Response.Redirect("Home.aspx");
            }
            else
            {
                GenerateLinks(Session["RoleId"].ToString());
                TopNavigationMenu.Enabled = true;
                NavigationMenu.Enabled = true;
                //TopNavigationMenu.Items[1].Text = "Support <img src='Images/bullet_arrow_down.png' alt='down' title='' />";

                if (Request.Url.ToString().Contains("Home"))
                    Response.Redirect("Default.aspx");

                if (!IsPostBack)
                {
                    string strPrevPg = "", strCurrPg = "";
                    if (Request.UrlReferrer != null)
                    {
                        strPrevPg = Request.UrlReferrer.AbsolutePath.ToString();
                        strPrevPg = strPrevPg.Substring(strPrevPg.IndexOf("/", 1) + 1, strPrevPg.Length - (strPrevPg.IndexOf("/", 1) + 1));
                        strPrevPg += Request.UrlReferrer.Query.ToString();
                    }
                    strCurrPg = Request.Url.AbsolutePath.ToString();
                    strCurrPg = strCurrPg.Substring(strCurrPg.IndexOf("/", 1) + 1, strCurrPg.Length - (strCurrPg.IndexOf("/", 1) + 1));

                    bool bFlag;
                    bFlag = Convert.ToBoolean(Session["goBackPg"]);

                    if (Session["PrevPg"] != null)
                    {
                        if (strCurrPg == Session["PrevPg"].ToString())
                        {
                            if (bFlag)
                            {
                                Session["CurrPg"] = strCurrPg;
                                Session["PrevPg"] = "Default.aspx";
                                bFlag = false;
                                Session["goBackPg"] = bFlag;
                            }
                            else
                            {
                                Session["CurrPg"] = strCurrPg;
                                Session["PrevPg"] = strPrevPg;
                            }
                        }
                        else
                        {
                            Session["CurrPg"] = strCurrPg;
                            Session["PrevPg"] = strPrevPg;
                            bFlag = false;
                            Session["goBackPg"] = bFlag;
                        }
                    }

                }
            }
        }
    }
    else
    {
        Response.Redirect("home.aspx");
    }
}

1 个答案:

答案 0 :(得分:0)

当您按后退按钮时,这些浏览器会向您显示缓存的内容。

您可以调试和检查,您的服务器没有被点击。此会话代码无效。

你可以tell the browser not to cache the page。这样,如果用户想要返回,他将不得不重新加载内容。