我 try catch 404 错误,例如 this...但是
- 当我尝试加载http://localhost:11415/wfwe/wefwe/时- 干得好。
- 当我尝试加载http://localhost:11415/order/时- 失败(出现错误RouteData 必须包含名为“action”且具有非空字符串值的项目。)
- 当我尝试加载http://localhost:11415/Images/时- 失败并出现错误文件不存在
我的路线:
routes.Add("Order", new LowercaseRoute("Order/{action}/{id}",
new RouteValueDictionary(
new
{
controller = "Order",
action = "",
id = UrlParameter.Optional
}),
new MvcRouteHandler()));
routes.Add("NotFound", new LowercaseRoute("{*url}", new RouteValueDictionary(
new
{
controller = "Pages",
action = "Http404",
}),
new MvcRouteHandler()));
为什么路由 NotFound - 不捕获所有 404 错误。当我尝试上传到我的主机并尝试 404 时,我收到此错误(NotFound 路线根本不起作用) 404 - 未找到文件或目录。 您正在查找的资源可能已被删除、更名或暂时不可用。
我整天都在处理这个问题,但没有什么......请帮助我
最佳答案
When i try to load http://localhost:11415/order/ - fail (with error The RouteData must contain an item named 'action' with a non-empty string value.)
因为这个:
new { controller = "Order", action = "", id = UrlParameter.Optional }
您需要指定一个操作。
When i try to load http://localhost:11415/Images/ - fail with error File does not exist
如果您的服务器上有 Images
文件夹,那么它将“拦截”请求,不让它们进入 MVC 管道。
关于asp.net - asp.net mvc 2 IIS 7 404错误如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2998068/