ASP.NET MVC3 短路径
我想要修改路由,并且需要有默认路由(控制器/操作/id),但我想将路由添加到从家庭控制器采取操作的短网址。我需要这样的东西:
routes.MapRoute(
"ActionOnly",
"{action}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
假设我家里有行动俱乐部。所以我想使用 adress.com/Club,但我仍然需要 adress.com/Articles(其中articles是控制器)。
我不知道该怎么做。有可能吗?或者我必须为所有事情制定这样的路线:
routes.MapRoute(
"Club",
"Club",
new {controller = "Home", action = "Club"}
);
谢谢
I want modified routing and I need to have default routing (controller/action/id) but I want to add route to short url which take action from home controller. I need something like this:
routes.MapRoute(
"ActionOnly",
"{action}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Let´s say I have action Club in Home. So I want to work adress.com/Club but still I need adress.com/Articles (where articles is controller).
I am not sure how to do that. Is it posible? Or I must for everything made route like this:
routes.MapRoute(
"Club",
"Club",
new {controller = "Home", action = "Club"}
);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您完全可以创建一个专门的路由来处理您想要的非常特殊的 URL。
路线引擎将在第一场比赛后停止。如果它找不到您的
俱乐部
,它将回退到默认俱乐部并响应文章
。请参阅此文档以获取更多信息关于它是如何工作的。
Yes, you can totally create a specialized route that will handle the very special URL like you want.
The route engine will stop after the first match. If it doesn't find your
Club
, it will fallback to the default one and responds to theArticles
.See this documentation to get more information about how it works.
您有在第一条路线中允许的操作列表吗?
路线.MapRoute(
“仅采取行动”,
“{行动}”,
新{控制器=“主页”,操作=“索引”,id=UrlParameter.Optional}
);
如果你想允许
routes.MapRoute(
“仅采取行动”,
“{行动}”,
新{控制器=“主页”,操作=“索引”,id=UrlParameter.Optional},
新的{行动=“俱乐部|另一个行动”}
);
希望这对您有帮助。
Do you have list of action that you allowed in first route ?
routes.MapRoute(
"ActionOnly",
"{action}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
If you want to allow
routes.MapRoute(
"ActionOnly",
"{action}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { action = "Club|AnotherActions"}
);
Hope this help you.