在ASP.NET中指定出错页面,不让代码外泄!在ASP.NET中原始的出错页面会暴露部分源代码,由此带来了潜在的安全隐患。 ASP.NET允许应用程序出错时显示用户指定的页面,方法是在web.config文件中修改配置信息。
上面的配置信息明确指定了当应用程序出错的时候显示用户定制的页面ErrorPage.htm。并且因为各个应用程序有自己独立的web.config配置文件,所以应用程序之间不会互相干扰。 其中,mode属性表示是否启用定制的用户页面,它可取三个值,如下所示: On 启用定制的出错页面 Off 禁用定制的出错页面 RemoteOnly 启用定制的出错页面但仅展示给远程用户 defaultRedirect属性表示用户定制出错页面的文件名。
ErrorPage.htm中,一般的内容是这样的:
英文:
中文:Internal Error We're sorry, an internal error occurred that prevents the request to complete.
Our supporting staff has been notified with this error and will address this issue shortly. We profusely apologize for the inconvenience and for any damage this may cause. You might want to try the same action at later time.
我们很抱歉。内部错误无法完成您的要求。
我们的支援人员已通知有此错误,将解决这一问题。我们对带来的不便深表歉意。你可以过一段时间再试一下。