在global.asax中定义多个路由不起作用 [英] Define multiple routing in global.asax not working

查看:199
本文介绍了在global.asax中定义多个路由不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net开发了网站。我有很多页面是基于模板的手段结构只是根据参数它的页面名称&内容变了。所以我在global.asax文件中定义了路由。问题是它只适用于顶部的一个页面。在下面的代码..



这里我有两个页面现在有不同的链接,但如果页面链接包含第二页,那么它也只被重定向到第一页。意味着如果我将页面路由到DynamicPage然后将其路由到shop2页面。如何解决这个问题以支持定义的路由。



我尝试过:



I have website developed in vb.net. I have many pages which is template based means structure is same just according to parameters it's page name & content gets changed. So I have define routing in my global.asax file. Problem is it is working only for one page which is on top. in following code..

Here I have two pages now with different links but if page link consist of second page then too it gets redirected to first page only. Means If I routed a page to DynamicPage then to it gets routed to shop2 page. How to solve this problem to support routing as defined.

What I have tried:

Private Sub Application_Start(sender As Object, e As EventArgs)
    RegisterRoutes(RouteTable.Routes)
End Sub

Private Shared Sub RegisterRoutes(routes As RouteCollection)
    routes.MapPageRoute("shop2", "{name}.aspx", "~/shop2.aspx")
    routes.MapPageRoute("DynamicPage", "{product_name}.aspx", "~/DynamicPage.aspx")
End Sub

推荐答案

从映射器的角度来看,这两个映射是相同的,所以适合第二个的所有东西也适合第一个,因此你永远不会重定向到第二个......

尝试这样的事情:

From the point of view of the mapper, these two mappings are the same, so everything that fits the second also fits the first and therefore you never will be redirected to the second...
Try something like this:
Private Shared Sub RegisterRoutes(routes As RouteCollection)
    routes.MapPageRoute("shop2", "{name}.aspx", "~/shop2.aspx")
    routes.MapPageRoute("DynamicPage", "product/{name}.aspx", "~/DynamicPage.aspx")
End Sub



在此处阅读更多内容: RouteCollection.MapPageRoute Method(System.Web.Routing) [ ^ ]


这篇关于在global.asax中定义多个路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆