简体   繁体   English

asp.net核心MVC区域路由,某些区域的routevalue参数

[英]asp.net core MVC area routing, routevalue params for some areas

I have a number of areas in my mvc app, and some of them require a route value, as a prefix to the whole route. 我的mvc应用程序中有很多区域,其中一些区域需要路由值,作为整个路由的前缀。 like this... 像这样...

mydomain.com/{routevalue}/{area}/{controller}/{action}/{id?} mydomain.com/{routevalue}/{area}/{controller}/{action}/{id?}

however, there are a couple of areas which do not use this routevalue and thus I would like them to respond to mydomain.com/{area}/{controller}/{action}/{id?} 但是,有几个区域不使用此路由值,因此我希望它们响应mydomain.com/{area}/{controller}/{action}/{id?}

I am trying to construct some route templates which cover this requirement, but not having much luck. 我正在尝试构建一些满足此要求的路由模板,但运气不佳。 I had initially added a new route for each area, such that the ones that didnt need the routevalue would not have that in the template. 最初,我为每个区域添加了一条新路线,这样不需要路由值的区域就不会在模板中包含该路线。 this was working fine when running locally is IIS express, but as soon as I deployed to IIS on a server, none of these area routes was responding, and instead I was getting a 404.. 当在IIS Express中本地运行时,此方法工作正常,但是当我将它部署到服务器上的IIS时,这些区域路由都没有响应,而是得到了404。

here is my current config 这是我当前的配置

routes.MapAreaRoute("YourAccountArea", "YourAccount", "YourAccount/{controller}/{action}/{id?}",
    defaults: new { area = "YourAccount", controller = "YourAccount", action = "Index" }); //<-- no product param on this area route

routes.MapAreaRoute("AboutYouArea", "AboutYou", "{product}/AboutYou/{controller}/{action}/{id?}",
    defaults: new { area = "AboutYou", product = "defaultproduct", controller = "AboutYou", action = "Index" });//<--this area does have the product prefix

routes.MapAreaRoute("SelectionArea", "Selection", "{product}/Selection/{controller}/{action}/{id?}",
    defaults: new { area = "Selection", controller = "SelectProduct", action = "Index" });//<--as does this

routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");//<--standard route

I am wondering if I can slim this down at all, and actually get it to respond on the server? 我想知道我是否可以瘦下来,并使其真正在服务器上响应? I do not currently have any Area or Route attributes on the controllers or actions (as I hadn't need them before) 我目前在控制器或操作上没有任何AreaRoute属性(因为我以前不需要它们)

edit: i then tried this: 编辑:我然后尝试这样做:

routes.MapRoute("areaNoProduct", "{area:exists}/{controller}/{action}/{id?}",
defaults: new { area = "YourAccount", controller = "YourAccount", action = "Index" });

routes.MapRoute(
   name: "areaRoute",
   template: "{product}/{area:exists}/{controller}/{action=index}/{id?}");

routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");

but not only does that pop the product as a querystring, but it doesnt generate the correct urls for actions, which I assume is the routing being incorrect 但不仅会以查询字符串的形式弹出产品,而且不会为操作生成正确的网址,我认为这是路由错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM