locked
HttpContext.Current.Request.RawUrl problem RRS feed

  • Question

  • User1456523893 posted

    Dim varRawUrl As String = HttpContext.Current.Request.RawUrl

    If varRawUrl.Contains("About") Then
    Context.RewritePath("/About.aspx")

    ElseIf  varRawUrl.Contains("AR/About") Then
    Context.RewritePath("/AR/About.aspx")

     End If

    when my link is ( http://localhost:50969/About ) redirect to (About.aspx)

    but when my link is ( http://localhost:50969/AR/About ) redirect  same page( About.aspx )  why don't redirect to  ("/AR/About.aspx")

    Tuesday, September 25, 2018 9:31 AM

Answers

  • User-369506445 posted

    hi

    yes, it's correct, because you use a  Contains and it's always true

     the one way for solving it change the if to below

    If varRawUrl.Contains("AR/About") Then
                Context.RewritePath("/AR/About.aspx")
            ElseIf varRawUrl.Contains("About") Then
                Context.RewritePath("/About.aspx")
    
            End If

    EDIT:

    a better way is to use <g data-gr-id="8" id="8" class="gr_ gr_8 gr-alert gr_spell ContextualSpelling ins-del multiReplace">startWith</g>

           If varRawUrl.StartsWith("/About") Then
                Context.RewritePath("/About.aspx")
            ElseIf varRawUrl.StartsWith("/AR/About") Then
                Context.RewritePath("/AR/About.aspx")
            End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 25, 2018 9:52 AM

All replies

  • User-369506445 posted

    hi

    yes, it's correct, because you use a  Contains and it's always true

     the one way for solving it change the if to below

    If varRawUrl.Contains("AR/About") Then
                Context.RewritePath("/AR/About.aspx")
            ElseIf varRawUrl.Contains("About") Then
                Context.RewritePath("/About.aspx")
    
            End If

    EDIT:

    a better way is to use <g data-gr-id="8" id="8" class="gr_ gr_8 gr-alert gr_spell ContextualSpelling ins-del multiReplace">startWith</g>

           If varRawUrl.StartsWith("/About") Then
                Context.RewritePath("/About.aspx")
            ElseIf varRawUrl.StartsWith("/AR/About") Then
                Context.RewritePath("/AR/About.aspx")
            End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 25, 2018 9:52 AM
  • User1456523893 posted

    tanks 

    vahid bakhtiary

    done 

    Tuesday, September 25, 2018 11:20 AM
  • User-369506445 posted

    I'm glad your problem has been resolved, if my post helped you, please mark as answer it

    Tuesday, September 25, 2018 1:42 PM