Home » Microsoft TechnologiesRSS

Response.Redirect problem in Google Chrome

I'm building an ASP.NET 3.5 webapplication using VB.NET, and I'm having problems redirecting to another URL when using Google Chrome. Other browsers like IE and Firefox are fine.

My data entry forms all have an OK and an Cancel button, which are both handled server-side. The Cancel button just redirects back to the originating page, while the OK button will add or update a database record and then redirect to the originating page.
The redirect to the originating page is done by calling the following shared sub on a general utilities class in my appication:

    Shared Sub Redirect(ByVal p_sURL As String)
        Dim l_sURL As String = p_sURL.ToLower
        If Left(l_sURL, 1) = "~" Then
            Dim l_oControl As New System.Web.UI.Control
            l_sURL = l_oControl.ResolveUrl(l_sURL)
        End If
        If Left(l_sURL, 1) <> "/" Then
            If Left(l_sURL, 7) <> "http://" AndAlso Left(l_sURL, 8) <> "https://" Then
                l_sURL = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) & wsUtils.SiteRoot & l_sURL
            End If
        End If
        HttpContext.Current.Response.Redirect(l_sURL)
        'HttpContext.Current.Response.Redirect(l_sURL, False)
    End Sub


As you can see, I've tried using the extra argument in the Response.Redirect call, but that doesn't make a difference.

All browsers except Google Chrome redirect fine, but Chrome does not redirect at all. When pushing the Cancel button nothing seems to happen. And when pushing the OK button, the corresponding database record is added or updated, but the redirect to the originating page doesn't happen.

This Chrome redirect problem occurs only on the production server. When running the application at 'localhost' there is no problem.

Any idea what might be causing this redirect issue in Google Chrome?

 

9 Answers Found

 

Answer 1

Chrome sucks...It caches 301 redirects

Refer this for more info : http://bugsquash.blogspot.com/2008/12/google-chrome-caches-301-redirects.html

Hope that helps Cool


 

Answer 2

Ya its true, Chrome caches 301 redirects, so Clearing cache might solve the problem.

Better to write and call  javascript function that contains

{ window.location.href = "RedirPageUrl"; }

 

Answer 3

kalpatel:

Ya its true, Chrome caches 301 redirects, so Clearing cache might solve the problem.

Better to write and call  javascript function that contains

{ window.location.href = "RedirPageUrl"; }

How would I trigger such a JavaScript function when the OK button  on an entry  form is clicked?

I can't put a client-side onClick handler on that button to trigger a client-side redirect, as I need the server-side  code to run first. And the redirect  should then only happen  when the server-side page  validation is done and the database  record was successfully added  or updated.


 

Answer 4

you can do like this..

protected void button_Click(object sender, EventArgs e)
        {
            // Your Code Here //
            string  RedirPageUrl = "url";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "someKeyRedir", "window.location.href = '" + RedirPageUrl + "';", true);
        }



 

Answer 5

kalpatel:

you can do like this..


protected void button_Click(object sender, EventArgs e)          {              // Your Code Here //              string RedirPageUrl = "url";              ClientScript.RegisterClientScriptBlock(this.GetType(), "someKeyRedir""window.location.href = '" + RedirPageUrl + "';"true);          }  


Regretfully that doesn't work. All browsers  now stay on the page  with the entry  form... no redirection.

 

Answer 6

Hi,

Yes, you can use JavaScript to perform redirection after executed server  side code and depends on some conditions. Please have a try.

' Use this code instead of HttpContext.Current.Response.Redirect(l_sURL)
HttpContext.Current.Response.Write("<script type='text/javascript'>window.location.href='" & l_sURL & "';</script>")

Have a nice day.

 

Answer 7

Wenchao Zeng - MSFT:

' Use this code instead of HttpContext.Current.Response.Redirect(l_sURL)  
HttpContext.Current.Response.Write("<script type='text/javascript'>window.location.href='" & l_sURL & "';</script>") 


Thank you for the suggestion, but this doesn't result in a redirect  to the other URL. And all browsers  now refuse to redirect again, not only Chrome.

 

Answer 8

When running  in debug mode, and using the 'Response.Write' method, I get an error like: "Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server  could not be parsed. Common causes for this error are when the response  is modified by calls to Response.Write(), response filters, HttpModules, 
or server trace is enabled. Details: Error parsing near ..."

The OK and Cancel buttons are inside an UpdatePanel, so that is likely the cause of the problem. 


But it's not so simple to put them outside the UpdatePanel, as the UpdatePanel is in the MasterPage, and the OK and Cancel buttons are on ContentPages.

Is there a solution to this without losing the UpdatePanel in the MasterPage?

 

Answer 9

I found my solution:


        Dim l_oSM As AjaxControlToolkit.ToolkitScriptManager = AjaxControlToolkit.ToolkitScriptManager.GetCurrent(Page)
        If l_oSM IsNot Nothing Then
            AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(Page, Page.GetType(), "wsReturnToPreviousPage", "window.location.href='" & l_sURL & "';", True)
        Else
            Page.ClientScript.RegisterStartupScript(Page.GetType, "wsReturnToPreviousPage", "window.location.href='" & l_sURL & "';", True)
        End If


I hope this helps anyone else who's struggling with the same issue  and finds this forum thread.

Thank you all who contributed to this topic!



 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter