【发布时间】:2012-08-03 09:54:12
【问题描述】:
对于一个项目,我必须(不幸地)匹配一些确切的 url。
所以我认为这不会有问题,我可以使用“MapRoute”,将 url 与所需的控制器匹配。但我不能让它工作。
我必须映射这个 URL:
http://{Host}/opc/public-documents/index.html
到
Area: opc
Controller: Documents
Action: Index
另一个例子是映射
http://{Host}/opc/public-documents/{year}/index.html
到
Area: opc
Controller: Documents
Action:DisplayByYear
Year(Parameter): {year}
我在我所在的地区尝试了这个,但没有成功(ocpAreaRegistration.cs):
context.MapRoute("DocumentsIndex", "opc/public-documents/index.html",
new {area="opc", controller = "Documents", action = "Index"});
context.MapRoute("DocumentsDisplayByYear", "opc/public-documents/{year}/index.html",
new {area="opc", controller = "Documents", action = "Action:DisplayByYear"});
但是当我尝试访问它时,我遇到了一些 404 错误 :(。我做错了什么?
【问题讨论】:
-
ocpAreaRegistration 什么时候被调用?它应该由 global.asax.cs 中的
RegisterRoutes调用 -
您不能对两条不同的路线使用相同的 maproute id。实际代码中是这样的吗?
-
@cellik 对不起,mapRoute Id,它只在示例中,错误的复制粘贴
-
@podiluska 因为它是为区域opc注册默认路由的文件(由VS2010在创建区域时创建),我想它应该已经被调用了。我尝试将这段代码直接放在 Global.asax.cs 中,但没有任何改变。
标签: asp.net-mvc routes friendly-url