通过 IIS 配置
-
按住 WIN + R 打开命令行输入 inetmgr 打开 IIS 管理
左边目录选择目标站点,在右边 IIS 块中双击 Error Pages
在 Error Pages 中右边的 Actions,选择 Edit Feature Settings
在 Error Responses 中,选择 Detailed errors,单机 OK 完成配置。
通过命令行
启用详细错误:
%windir%system32inetsrvappcmd.exe set config "Default Web Site/yourapp" /section:httpErrors /errorMode:Detailed
禁用详细错误:
%windir%system32inetsrvappcmd.exe set config "Default Web Site/yourapp" /section:httpErrors /errorMode:Custom
通过 web.config 配置
其实,上面在两种配置,最终都会反应到对应的 web.config 中。因此,我们可以直接编辑 web.config。特别是对于买的虚拟主机(Shared Web Hosting),没有权限更改IIS。打开网站目录,找到 web.config 文件(如果没有,就建立一个 txt 文件存为 web.config),找到 system.webServer 配置节,添加配置 <httpErrors errorMode="DetailedLocalOnly" />。
<configuration><system.webServer>
<httpErrors errorMode="DetailedLocalOnly" />
</system.webServer>
</configuration>
注意
此参数选项可以应用到网站或子目录或虚拟目录。 此参数选项对所有 IIS 应用程序有效,包括 ASP, APS.NET, PHP 等。
如果是 ASP.NET 程序,可能还需要配置 <customErrors mode=”Off” />









