[英]default URL Routing with ASP.NET 4 Web Forms
it seem that we need to specify a route for every page in webform routing 似乎我们需要为网络表单路由中的每个页面指定路由
I want to use default route to a page called cms.aspx with parametr called nameofurl for each page expect default.aspx 我想用默认路由到一个名为页面cms.aspx与parametr称为nameofurl的期望 Default.aspx的每一页
sometimes I want to send the cms.aspx more then one parametrs,for example 有时我想发送cms.aspx而不是一个参数,例如
mydomain.com/cms.apx?nameurl=somevalue mydomain.com/cms.apx?nameurl=somevalue
or 要么
mydomain.com/cms.apx?nameurl=somevalue&order=6 mydomain.com/cms.apx?nameurl=somevalue&order=6
I have this code but it isn't the solution since you have to tell the routing the name of the page 我有这段代码,但这不是解决方案,因为您必须告诉路由页面的名称
routes.MapPageRoute("",
"pageName/{nameofurl}",
"~/cms.aspx")
I want something like this 我想要这样的东西
routes.MapPageRoute("",
"?/{nameofurl }",
"~/cms.aspx")
sometimes I want it to be like this 有时候我希望它像这样
routes.MapPageRoute("SalesRoute",
"?/{nameofurl}/{order}",
"~/cms.aspx");
any idea how to Achieve that kind of routing without specify the name of the page? 不知道如何在不指定页面名称的情况下实现这种路由?
You can create routes like given below: 您可以创建如下所示的路线:
routes.MapPageRoute("Route1","{nameofurl}","~/cms.aspx")
routes.MapPageRoute("Route2","{nameofurl}/{order}","~/cms.aspx")
routes.MapPageRoute("Route3","{nameofurl}/{order}/{abc}","~/cms.aspx")
The above routes will work if there are no other pages with 2 or 3 parameters. 如果没有其他带有2或3个参数的页面,上述路由将起作用。 But if there is some other page which you want to route and which has 2 parameters to be passed, then you need to mention a hard-coded string before the parameters otherwise the new route will override the old route. 但是,如果还有其他要路由的页面并且要传递2个参数,则需要在参数之前提及一个硬编码字符串,否则新路由将覆盖旧路由。
For Example: 例如:
routes.MapPageRoute("Route4","{nameofurl}/{order}","~/products.aspx")
In the above case, Route4 will override Route 2. Thus, you need to define route something like below: 在上述情况下,Route4将覆盖Route2。因此,您需要定义以下路由:
routes.MapPageRoute("Route4","products/{nameofurl}/{order}","~/products.aspx")
You can find URL Routing related articles at following URLs: 您可以在以下URL中找到与URL路由相关的文章:
http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-part-2.html http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-part-2.html
Thanks & Regards, 感谢和问候,
Munjal 芒贾尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.