且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.Net MVC的路由映射

更新时间:2023-02-16 16:39:45


  

我刚才已经回答我的问题。我有
  向后路由(默认值是
  以上页)。


块引用>

是的,你必须把默认路由首先定制路由。


  

因此​​,这带来了下一个问题......
  请问在默认路由匹配(我
  假设他们使用常规的前pressions
  这里)页面路线?


块引用>

根据我们称之为约定优于配置默认的路由匹配。斯科特格思里解释了它很好在ASP.NET MVC他的第一个博客帖子。我建议你​​阅读它也是他的其他职务。请记住,这些是基于所述第一CTP发布,框架已经改变。您还可以找到关于ASP.NET MVC网络直播由斯科特Hanselman的的asp.net网站。

I'm new to MVC (and ASP.Net routing). I'm trying to map *.aspx to a controller called PageController.

routes.MapRoute(
   "Page",
   "{name}.aspx",
   new { controller = "Page", action = "Index", id = "" }
);

Wouldn't the code above map *.aspx to PageController? When I run this and type in any .aspx page I get the following error:

The controller for path '/Page.aspx' could not be found or it does not implement the IController interface. Parameter name: controllerType

Is there something I'm not doing here?

I just answered my own question. I had the routes backwards (Default was above page).

Yeah, you have to put all custom routes above the Default route.

So this brings up the next question... how does the "Default" route match (I assume they use regular expressions here) the "Page" route?

The Default route matches based on what we call Convention over Configuration. Scott Guthrie explains it well in his first blog post on ASP.NET MVC. I recommend that you read through it and also his other posts. Keep in mind that these were posted based on the first CTP and the framework has changed. You can also find web cast on ASP.NET MVC on the asp.net site by Scott Hanselman.