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>
参考问题: