如何获得干净的ASP.Net错误页面?
|
当我在IIS(6.0)上的ASP.Net(3.5)站点上出现应用程序错误时,我得到了脏 HTML代码. 我希望自动生成XHTML代码,对于解析答案的Web服务会很好…(我对编写自定义页面不感兴趣). 有没有办法指定它? 编辑:示例 这里是例如,生成的404错误的页面,我想干净的XHTML代码,但我不想自己编写,ASP.Net模块可以做到吗? <html>
<head>
<title>La ressource est introuvable.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Erreur du serveur dans l'application '/</b>/MyVirtualDirectory'.<hr width=100% size=1 color=silver></H1>
<h2> <i>La ressource est introuvable.</i> </h2></span>
<font face="Arial,Helvetica,Geneva,SunSans-Regular,sans-serif ">
<b> Description : </b>HTTP 404. ...
<br><br>
<b> URL demandée: </b>/MyVirtualDirectory/MyService.aspx<br><br>
<hr width=100% size=1 color=silver>
<b>Informations sur la version :</b> Version Microsoft .NET Framework :2.0.50727.3053; Version ASP.NET :2.0.50727.3634
</font>
</body>
</html>
编辑 我猜,上面的HTML是由ASPX页面生成的,有没有可以找到它的地方?为了获得灵感并在XHTML中进行翻译,我将使用@Remko 3rd解决方案来指定自定义错误页面. 解决方法有几种方法可以处理ASP.NET中的错误并控制响应的内容.注意:所有方法都要求您编写自己的自定义XHTML代码(尽管您注意到您对编写自定义页面不感兴趣) >在页面级别:向页面添加Page_Error事件处理程序. public void Page_Error(object sender,EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
Response.Write("<p>Your perfectly formatted XHTML code.</p>");
Server.ClearError();
}
如果您调用Server.ClearError(),ASP.NET将不会处理该错误,您将无法获得默认错误页面. protected void Application_Error(object sender,EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
Response.Write("<p>Your perfectly formatted XHTML code.</p>");
Server.ClearError();
}
>在web.config文件中指定自定义错误页面 <customErrors mode="On" defaultRedirect="myperfectxhtmlerror.aspx" > 有关更详细的说明,请参阅:How to create custom error reporting pages in ASP.NET (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 防止XSS(跨站脚本)
- asp.net-mvc-routing – 如何防止Url.RouteUrl(…)从当前请
- Asp.NET DropDownList在PostBack之后重置SelectedIndex
- 使用ASP.Net编辑表格 – Quick’n Dirty
- asp.net-mvc-3 – MVC 3 knockoutjs:在使用EditorFor作为布
- asp.net-core – .net core(csproj)global.json’projects’
- asp.net – 如何调试Azure 500内部服务器错误[已关闭]
- asp.net-mvc – Asp.Net MVC3 RC Razor视图:在块内嵌入代码
- ASP.net Web服务与WCF
- asp.net – jQuery模态窗体对话框回发问题
