问题描述
我试图创建一个简单的网站。基本上,它有一个控制器首页
控制器。
I'm trying to create a simple site. Basically it has one Controller Home
controller.
该控制器具有一个动作首页
需要字符串
作为参数(这是一个目录),并使用了目录来完成工作。
This controller has an action Index
takes a string
as argument (which is a directory) and uses that 'directory' to do its work.
我不知道如何创建一个通用的追赶,将每个URL发送到这个行动的所有航线。
I can't work out how to create a generic catch all route that will send every URL to this one Action.
任何URL组合可以存在的,任何超出该域名应该是字符串。
Any URL combination could exist, and anything beyond the domain name should be the string.
的http://&LT结构域GT; / 2008
的http://&LT结构域GT; / 2008/09
的http://&LT结构域GT; / 2008/09 /弗雷德
有谁知道如何做到这一点?这也将是正常的,如果所有的值都为列表过去了。
Does anyone know how to do this? It would also be alright if all the values are passed as a list.
是否有这样做的更好的办法?
Is there a better way of doing this?
推荐答案
试试这个:
routes.MapRoute(
"Default", "{*path}",
new { controller = "Home", action = "Index" }
);
和控制器:
public class HomeController : Controller {
public ActionResult Index(string path) {
return View();
}
}
这篇关于ASP.NET MVC路由的单控制器网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!