【发布时间】:2015-06-19 12:14:31
【问题描述】:
我想创建带有 2 个参数的 Web 应用程序。将此代码添加到 RegisterRoutes 函数中:
routes.MapRoute(
"pageroute",
"page/{pageid}/{pagename}",
new { controller = "page", action = "Index", pageid = "", pagename = "" }
);
并在pageController中添加此方法:
public ActionResult Index(int pageid,string pagename)
{
return View();
}
现在当我使用这个参数运行应用程序时
http://localhost:1196/page/4/Pagename
应用程序运行成功,但使用此参数运行时
http://localhost:1196/page/4/Pagename.html
应用程序返回 404 错误
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
在参数中添加 .html 时返回 404 错误。 为什么?
【问题讨论】:
-
当 ulr 包含“.html”时,请求会转到 html 管道以在 iis 处处理请求。您必须通过 ASP.NET 管道强制所有请求。
-
同意圣普拉迪普
-
@SainPradeep 如何强制使用 ASP.net 处理请求?
-
@dinav Ahrie 我使用 MVC 没有 .aspx 文件,当用户调用此 URL 应用程序从数据库加载 page1.html 并创建页面并返回给用户时,page1.html 是保存在我的数据库中的页面名称
标签: asp.net asp.net-mvc