mvc怎么请求服务器错误信息,asp.net-mvc – IIS显示服务器错误而不是自定义错误...
我正在使用MVC 5,我正在使用自定義視圖處理我的錯誤,例如(404,403 ……等)
它在我的本地IIS上工作正常,但是當我在登臺服務器上發布時,它顯示有關這些錯誤代碼的IIS服務器錯誤消息.
它顯示了這條消息:
代替:
我修改了web.config for< customErrors mode =“Off”/>
Global.asax中
if ((Context.Server.GetLastError() is UnauthorizedAccessException))
{
log.LogError(Context.Server.GetLastError().Message,Context.Server.GetLastError());
customErrorPage = @"~/Error/?id=403"; //security
}
else if ((Context.Server.GetLastError() is HttpException) && (((HttpException)Context.Server.GetLastError()).GetHttpCode() == 404))
{
//** Handle 404 error and response code
log.LogError("404",Context.Server.GetLastError());
customErrorPage = @"~/Error/?id=404";
}
else
{
log.LogError(Context.Server.GetLastError().Message,Context.Server.GetLastError());
customErrorPage = @"~/Error";
}
if (ConfigurationHelper.Common.ShowCustomErrorPage)
{
var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
Response.Redirect(urlHelper.Content(customErrorPage),false);
Server.ClearError();
}
錯誤控制器:
public ActionResult Index(string id)
{
if (!string.IsNullOrEmpty(id) && id.Equals("404"))
{
Response.StatusCode = 404;
return !Request.IsAjaxRequest() ? (ActionResult)View("404") : PartialView("404");
}
if (!string.IsNullOrEmpty(id) && id.ToLower().Equals("403"))
{
Response.StatusCode = 403;
return !Request.IsAjaxRequest() ? (ActionResult)View("Security") : PartialView("Security");
}
return !Request.IsAjaxRequest() ? (ActionResult)View("Index") : PartialView("Index");
}
我應該怎么做以顯示我的自定義錯誤消息?
總結
以上是生活随笔為你收集整理的mvc怎么请求服务器错误信息,asp.net-mvc – IIS显示服务器错误而不是自定义错误...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 挖掘机一个台班多少钱啊?
- 下一篇: java调用外联服务用xml,Sprin