trouble with url rewriting RRS feed

  • Question

  • User1961461639 posted


    I have a little trouble with url rewriting so I turn to you after a few days of searching without success ^ ^

    Rather than a large blabla I go directly to the example will be clearer.
    If I put the redirect directly in my page it works fine, the page is rewritten no worries


    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%$RouteUrl:RouteName=RechercheParMarqueAuto,i=Audi%>">HyperLink</asp:HyperLink>

    Résultat :



    But the real problem comes when I go through the code behind, the url isn't rewritten


    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="#" />


    strNomMarque = "Audi"
    strUrlPageMarques = "<%$RouteUrl:RouteName=RechercheParMarqueAuto,i=" & strNomMarque & "%>"
    HyperLink1.NavigateUrl = strUrlPageMarques
    HyperLink1.ToolTip = strNomMarque
    HyperLink1.Text = strNomMarque

    Résultat :


    Why ? Cry


    If it helps this is what I have in the Global.asax

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    End Sub
    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.MapPageRoute("RechercheParMarqueAuto", "Marque/{i}", "~/recherche-par-marque-auto.aspx")
    End Sub

    Thank you for helping out Wink

    Wednesday, April 3, 2013 5:17 AM

All replies

  • User1508394307 posted


    Dim parameters As RouteValueDictionary
    parameters = New RouteValueDictionary(New With _
             {.i = "Audi"})
    Dim vpd As VirtualPathData
    vpd = RouteTable.Routes.GetVirtualPath(Nothing, "RechercheParMarqueAuto", parameters)
    HyperLink1.NavigateUrl = vpd.VirtualPath



    Hope this helps.

    Wednesday, April 3, 2013 6:00 AM
  • User1961461639 posted

    It's ok, thanks !!! Smile

    However, I get an error vpd.VirtualPatch with Response.Redirect

    strNomMarque = "Audi"
    Dim parameters As RouteValueDictionary
    parameters = New RouteValueDictionary(New With {.i = strNomMarque })
    Dim vpd As VirtualPathData
    vpd = RouteTable.Routes.GetVirtualPath(Nothing, "RechercheParMarqueAuto", parameters)

    Error :

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    (Détails de l'exception: System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet. )

    and if I use

    Response.RedirectToRoute("RechercheParMarqueAuto", New RouteValueDictionary(New With {.i = strNomMarque }))


    Response.RedirectToRoute("RechercheParMarqueAuto", New With {.i = strNomMarque})

    Error :

    Exception Details: System.InvalidOperationException: No matching route found RedirectToRoute.
    (Détails de l'exception: System.InvalidOperationException: Aucun itinéraire correspondant trouvé pour RedirectToRoute.)

    Thank for your help

    Thursday, April 4, 2013 10:10 AM