Response.Redirect with a fragment identifier causes unexpected refresh when later using location.hash

后端 未结 2 1408
孤独总比滥情好
孤独总比滥情好 2020-12-18 09:15

I was hoping someone can assist in describing a workaround solution to the following issue I am running into on my ASP.NET website on IE. In the following I will describe th

2条回答
  •  旧时难觅i
    2020-12-18 09:43

    This will happen in IE if there's a directive that forbids caching on the post-redirection page. If you remove the No-Cache header, you will find that the problem no longer repros.

    Here's a Meddler script that demonstrates the behavior:

    import Meddler;
    import System;
    import System.Net.Sockets;
    import System.Windows.Forms;
    
    class Handlers
    {
        static function OnConnection(oSession: Session)
        {
            if (oSession.ReadRequest())
            {       
                var oHeaders: ResponseHeaders = new ResponseHeaders();
                oHeaders["Connection"] = "close";
    
                if (oSession.urlContains("postRedir.asp"))
                {
                    oHeaders.Status = "200 OK";
                    oHeaders["Content-Type"] = "text/html"; 
                    oHeaders["Cache-Control"] = "no-cache";
                    oSession.WriteString(oHeaders);
                    oSession.WriteString("");
                    oSession.WriteString("Top of page





    "); oSession.WriteString("



    Div with ID firstAnchor
    Click this link: #secondAnchor"); oSession.WriteString("

















    "); oSession.WriteString("








    Div with ID secondAnchor"); } else if (oSession.urlContains("doRedir.asp")) { oHeaders.Status = "301 Redir"; oHeaders["Location"] = "/postRedir.asp#firstAnchor"; oSession.WriteString(oHeaders.ToString()); } else { oHeaders.Status = "200 OK"; oHeaders["Content-Type"] = "text/html"; oSession.WriteString(oHeaders); oSession.WriteString("This is a test case for http://stackoverflow.com/questions/1985056/response-redirect-with-a-fragment-identifier-causes-unexpected-refresh-when-later
    "); oSession.WriteString("Click this link: Do Redirect"); oSession.WriteString("
    "); } } oSession.CloseSocket(); } }

提交回复
热议问题