| 自定义了错误页面,但IIS却显示http服务器内部500错误的解决办法
					当前位置:点晴教程→知识管理交流
					
					→『 技术文档交流 』
					
				 
 1. 激活异常过滤器 当自定义异常被捕获时,异常过滤器变为可用。为了能够获得自定义异常,打开Web.config文件,在System.Web.Section下方添加自定义错误信息。    <system.web>      <customErrors mode="On"></customErrors>3. 绑定异常过滤器 将过滤器绑定到action方法或controller上,不需要手动执行,打开 App_Start folder文件夹中的 FilterConfig.cs文件。在 RegisterGlobalFilters 方法中会看到 public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            //filters.Add(new AuthorizeAttribute());
        }
    }如果需要删除全局过滤器,那么会将过滤器绑定到action 或controller层,如下:    [AdminFilter]   [HandleError]   public async Task<ActionResult> Upload(FileUploadViewModel model)@model HandleErrorInfo
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width" />
    <title>错误</title>
</head>
<body>
    <hgroup>
        <h1>错误。</h1>
        <h2>处理你的请求时出错。</h2>
    </hgroup>
    Error Message :@Model.Exception.Message<br />
    Controller: @Model.ControllerName<br />
    Action: @Model.ActionName
</body>
</html>5. 运行后故意出错,显示的却是http服务器内部500错误,并不显示Error中的自定义错误信息。解决办法: 转载 该文章在 2025/8/22 15:22:40 编辑过 | 关键字查询 相关文章 正在查询... |