locked
Doing a script in global.asax to redirect to some pages RRS feed

  • Question

  • User545494261 posted

    Hi all:

    I have some pc version aspx pages and mobile.

    When the device is a mobile I redirect to the mobile version.

    I have in global.asax

        Sub Session_Start(sender As Object, e As EventArgs)
            If HttpContext.Current.Request.Browser.IsMobileDevice Then
                Dim blnpaginamovil As Boolean = HttpContext.Current.Request.Path.StartsWith("Respequena", StringComparison.OrdinalIgnoreCase)
                'palabras de comienzo del path
                If Not blnpaginamovil Then
                    'new path -mal, I don't know how to get the actual path-
                    'the redirect should be Respequena/Cresolia/default.aspx?idioma=<%=IIf(Request.QueryString("idioma") IsNot Nothing, Request.QueryString("idioma"), 1)%>
                    'or Respequena/Ocio/default.aspx?idioma=<%=IIf(Request.QueryString("idioma") IsNot Nothing, Request.QueryString("idioma"), 1)%>
                    'depending if there is Cresolia or Ocio in the actual path
                    HttpContext.Current.Response.Redirect("Respequena")
                End If
            End If
        End Sub
    

    Do u know how to do the script and get the actual path.?

    Thanks in advance

    Friday, July 24, 2020 8:31 AM

Answers

  • User-939850651 posted

    Hi volar.2016,

    I think your method can solve your current problem.

    At first, use Request.Browser.IsMobileDevice Property determines whether it is a mobile device, and then determines whether it needs

    to redirect mobile version according to the current route. 

    What you need to do is to pay attention to the problem of Url splicing.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2020 10:28 AM

All replies

  • User545494261 posted

    Hi all again:

    The global.asax is now

        Sub Session_Start(sender As Object, e As EventArgs)
            If HttpContext.Current.Request.Browser.IsMobileDevice Then
                Dim blnpaginamovil As Boolean = HttpContext.Current.Request.Path.StartsWith("Respequena", StringComparison.OrdinalIgnoreCase)
                'palabras de comienzo del path
                If Not blnpaginamovil Then
                    HttpContext.Current.Response.Redirect("Respequena/" & HttpContext.Current.Request.RawUrl)
                End If
            End If
        End Sub
    

    Is it okey to get the mobile version of  my pages?

    Thanks in advance.

    Friday, July 24, 2020 10:04 AM
  • User-939850651 posted

    Hi volar.2016,

    I think your method can solve your current problem.

    At first, use Request.Browser.IsMobileDevice Property determines whether it is a mobile device, and then determines whether it needs

    to redirect mobile version according to the current route. 

    What you need to do is to pay attention to the problem of Url splicing.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2020 10:28 AM