ASP.NET MVC 默认路由? [英] ASP.NET MVC Default route?

查看:26
本文介绍了ASP.NET MVC 默认路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的 ASP.NET MVC 项目并实现了站点授权过滤器.

I created a new ASP.NET MVC project and implemented a site authorization filter.

当我将路由映射到 {controller}/{action} 对时,我将一个 role = "SomeRole" 默认值传递给路由.

When I map the routes to the {controller}/{action} pair, I pass a role = "SomeRole" default to the route.

如果我通过完整的 url (http://localhost/somecontroller/someaction) 并且我指定了完整的路由

It works perfectly if I go through the full url (http://localhost/somecontroller/someaction) and I specified the full route

MapRoute("SomeAction", "somecontroller/someaction",
 new { controller = "SomeController", action = "SomeAction", role = "SomeRole");

问题是当有人访问 http://thesiteaddress.com 时,必须有一个默认路由调用 /home/index 而不是 / 如果我指定

The problem is that when somebody visits http://thesiteaddress.com there has to be a default route that invokes /home/index instead of / and if I specify

MapRoute("Default", new { controller="somecontroller",action="action" });

然后我丢失了之前 MapRoute 中的 role="SomeRole".

then I lose the role="SomeRole" from the previous MapRoute.

我该如何解决这个问题?

How can I solve this?

推荐答案

确保 Default 路由位于您列出的路由表的BOTTOM.当涉及到 ASP.NET MVC 路由表时,顺序很重要.

Make sure the Default route is at the BOTTOM of your listed route table. Order matters when it comes to ASP.NET MVC Routing tables.

正确的排序是从最具体"的路线到最不具体的路线.

The correct ordering is your 'most specific' route to your least specific route.

这篇关于ASP.NET MVC 默认路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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