Asp.net 404自定义错误页面Mvc3仅适用于不存在的路由
浏览了100个关于这个主题的链接后,我找不到解决问题的方法。我正在手动处理404自定义错误页面,如下所示 当我在地址栏中键入任何错误的url并正确显示404错误页面时,我下面的解决方案就会起作用。但是当我打字的时候http://localhost:57101/p/any 或http://localhost:57101/p/123 它显示网页不可用。对于第一个错误,参数id的错误不能包含空条目。第二个是产品id,它被删除,所以产品为空,所以我在那里抛出手动异常 我的web.config设置为Asp.net 404自定义错误页面Mvc3仅适用于不存在的路由,asp.net,asp.net-mvc-3,http-status-code-404,custom-error-pages,httpexception,Asp.net,Asp.net Mvc 3,Http Status Code 404,Custom Error Pages,Httpexception,浏览了100个关于这个主题的链接后,我找不到解决问题的方法。我正在手动处理404自定义错误页面,如下所示 当我在地址栏中键入任何错误的url并正确显示404错误页面时,我下面的解决方案就会起作用。但是当我打字的时候http://localhost:57101/p/any 或http://localhost:57101/p/123 它显示网页不可用。对于第一个错误,参数id的错误不能包含空条目。第二个是产品id,它被删除,所以产品为空,所以我在那里抛出手动异常 我的web.config设置为 &l
<customErrors mode="On" redirectMode="ResponseRedirect">
</customErrors>
当我尝试浏览任何不存在的路由时,上面的代码都会起作用。
但当我抛出如下异常时
我的错误控制器是
public class ErrorsController : Controller
{
//
// GET: /Errors/
public ActionResult General(Exception exception)
{
Response.ContentType = "text/html";
Response.TrySkipIisCustomErrors = true;
return View();
}
public ActionResult Http404()
{
//return Content("Not found", "text/plain");
Response.ContentType = "text/html";
Response.TrySkipIisCustomErrors = true;
return View();
}
public ActionResult Http403()
{
Response.ContentType = "text/html";
Response.TrySkipIisCustomErrors = true;
return View();
}
}
public ActionResult Product(int productId)
{
var product = _productService.GetProductById(productId);
if(product==null)
throw new HttpException(404, "Product does not exists");
}
显示此网页不可用
我还想保持url,就像stackoverflow一样
有关此问题的任何帮助。尝试此操作,但相同的结果适用于不存在的路由,但不适用于引发异常manuallyNobody遇到了与我相同的问题?不,我们可以删除此问题,因为我正在设置应用程序错误中的else条件如何/何时在应用程序错误中遇到else条件?
public class ErrorsController : Controller
{
//
// GET: /Errors/
public ActionResult General(Exception exception)
{
Response.ContentType = "text/html";
Response.TrySkipIisCustomErrors = true;
return View();
}
public ActionResult Http404()
{
//return Content("Not found", "text/plain");
Response.ContentType = "text/html";
Response.TrySkipIisCustomErrors = true;
return View();
}
public ActionResult Http403()
{
Response.ContentType = "text/html";
Response.TrySkipIisCustomErrors = true;
return View();
}
}
public ActionResult Product(int productId)
{
var product = _productService.GetProductById(productId);
if(product==null)
throw new HttpException(404, "Product does not exists");
}