ASP.NET MVC默认路由? [英] ASP.NET MVC Default route?
问题描述
我创建了一个新的ASP.NET MVC项目并实现了一个网站授权过滤器。
I created a new ASP.NET MVC project and implemented a site authorization filter.
当我到 {控制器} / {行动}
对路线图,我通过一个角色=SomeRole默认的路由。
When I map the routes to the {controller}/{action}
pair, I pass a role = "SomeRole" default to the route.
它完美,如果我去通过完整的URL(的http://本地主机/ 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
必须有一个调用 /家庭/指数<默认路由/ code>而不是
/
如果我指定
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" });
然后我失去了角色=SomeRole
从previous 图路线
。
then I lose the role="SomeRole"
from the previous MapRoute
.
我该如何解决呢?
推荐答案
确保默认
路线为您列出的路线在底表。当涉及到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屋!