IIS 7.5 Windows 2008 R2提供500远程和自定义404本地
本文关键字:自定义 404本地 提供 Windows 2008 R2 IIS | 更新日期: 2023-09-27 17:49:58
我已经创建了以下基本控制器来显示InvalidOperationException上的自定义404(例如未找到视图)。
public class HandlesViewNotFoundController : Controller
{
protected override void OnException(ExceptionContext filterContext)
{
//InvalidOperationException is thrown if the path to the view
// cannot be resolved by the viewengine
if (filterContext.Exception is InvalidOperationException)
{
if (!filterContext.ExceptionHandled)
{
filterContext.ExceptionHandled = true;
filterContext.Result = new ViewResult { ViewName = "_404" };
filterContext.HttpContext.Response.StatusCode = 404;
Response.Clear();
// Clear the error on server.
Server.ClearError();
// Avoid IIS7 getting in the middle
Response.TrySkipIisCustomErrors = true;
}
}
base.OnException(filterContext);
}
}
由于某些原因,当我打开一个会触发404的页面时,它在调试时在本地运行良好,在服务器上查看页面时在本地运行良好,但如果我在远程服务器上查看相同的url,则返回内部服务器错误(500)。
任何想法?
检查web中的customeErrors属性是否配置正确。配置(以及部署的转换)并注释掉全局过滤器HandleError。
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
//filters.Add(new HandleErrorAttribute());
}
您可能忘记将视图文件_404部署到服务器。