我在asp.net Web表单中有网站。它使用URL友好结构。假设我有URL www.site.com/experience/experience-category 。这里有两个不同的页面经验&经验类别。现在,每当我尝试访问此URL www.site.com/experience/experience-category 时,它不会显示此页面。它向我展示了www.site.com/Experience页面。如何解决?
RouteConfig
Public Module RouteConfig
Public Sub RegisterRoutes(routes As RouteCollection)
Dim settings = New FriendlyUrlSettings()
settings.AutoRedirectMode = RedirectMode.Permanent
routes.EnableFriendlyUrls(settings)
routes.MapPageRoute("experience-category", "experience/{name}", "~/experience-category.aspx") 'For Experience Category
End Sub
End Module
您可以做很多事情。
routes.EnableFriendlyUrls(settings)
基本上要做的是在您的路由集合中添加2条路线。
您的问题是您拥有一个.aspx(cerseapen.aspx),其名称与您设置的路线URL的一部分相同(experience/{name}
)。该路由将在您的路由集合中寻找第一场比赛(在这种情况下,它将是您的EnableFriendlyUrls
路线)。
如果要克服这一点,则可以执行以下操作:
1.Execute routes.mappageroute在路由之前。 Public Module RouteConfig
Public Sub RegisterRoutes(routes As RouteCollection)
routes.MapPageRoute("experience-category", "experience/{name}", "~/experience-category.aspx") 'For Experience Category
Dim settings = New FriendlyUrlSettings()
settings.AutoRedirectMode = RedirectMode.Permanent
routes.EnableFriendlyUrls(settings)
End Sub
End Module
Public Module RouteConfig
Public Sub RegisterRoutes(routes As RouteCollection)
routes.MapPageRoute("experience-category", "experience/{name}", "~/experience-category.aspx") 'For Experience Category
Dim settings = New FriendlyUrlSettings()
settings.AutoRedirectMode = RedirectMode.Permanent
routes.EnableFriendlyUrls(settings)
End Sub
End Module
这将把这个规则放在第一位,击败友好的肉体设置:
或
2。使用插入物在路由集合的开始时插入您的规则(而不是mappageroute):
Dim settings = New FriendlyUrlSettings()
settings.AutoRedirectMode = RedirectMode.Permanent
routes.EnableFriendlyUrls(settings)
Dim overwrExperienceUrl As String = "experience/{name}"
Dim overwrExperiencePRH As New PageRouteHandler("~/experience-category.aspx")
Dim overwrExperienceRoute As New Route(overwrExperienceUrl, overwrExperiencePRH)
routes.Insert(0, overwrExperienceRoute)
3.避免与启用友谊路由规则的匹配:
将您的控件(s)(a)