带路由的页面导航

时间:2012-07-17 14:36:42

标签: asp.net routing

我在Global.asax文件中有这个代码:

 Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        RegisterRoute(RouteTable.Routes)
    End Sub
    'about.aspx
    Sub RegisterRoute(ByVal _routes As RouteCollection)
        With _routes
            .MapPageRoute("homepage", "Home", "~/default.aspx")
            .MapPageRoute("aboutpage", "About", "~/about.aspx")
            .MapPageRoute("producs", "Products", "~/products/Default.aspx")
            .MapPageRoute("adFin", "Products/{name}", "~/products/Default.aspx")
            .MapPageRoute("news", "News", "~/news.aspx")
            .MapPageRoute("contact", "Contact", "~/contact.aspx")

        End With
    End Sub

任何时候我导航到Product / Myproductname它工作正常但如果我导航回家,网址仍然是Product / Home而不是Home

1 个答案:

答案 0 :(得分:0)

我的想法是你可能通过ActionLink方法生成你的链接 - 它使用当前的Controller,即“Product”。您可能想要在没有HtmlHelper的情况下手动创建链接---只需链接到Home

即可