您的位置:首页 > 编程语言 > ASP

【记录】ASP.NET MVC MapRoute .htm 不起作用

2014-12-15 13:39 435 查看
RegisterRoutes 注册路由示例配置:

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "default",
url: "n/index_{id}.htm",
defaults: new { controller = "Home", action = "Index" });
}

Controller 示例代码:

public class HomeController : Controller
{
// GET: Home
public ActionResult Index(int id)
{
return View();
}
}

测试环境是 ASP.NET MVC 5,如上配置,会抛出“404错误”,如果把 url 更改为:
n/index_{id}.aspx
,却是可以的,不知道具体是什么原因,解决方式是在 Web.config 中添加如下配置:

<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

参考问题:

Adding Html in ASP.Net MVC
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: