新人求助,一道初级面试题。 如果在一个B/S项目代码里没有执行try……catch,但又需要每次发生异常都跳转到一个友好的提示页面,而该项目中有上百个页面,不可能每个页面都再去加try……catch,请问你如何解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Global.asax中写: void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 Response.Redirect("友好提示页面.html"); } web.config怎么实现?看那个传送门内容没看懂。 自定义错误页Error.aspx,通过webconfig.xml的错误配置,或在Global.asax捕获整个解决方案中的异常错误。webconfig.xml:<configuration> <system.web> <customErrors mode="On" defaultRedirect="Error.aspx"/> </system.web> </configuration>Global.asax:protected void Application_Error(object sender, EventArgs e) { try { Server.Transfer("Error.aspx"); } catch { } } Error.aspx:Exception ex = Server.GetLastError().GetBaseException(); if (ex != null) { Response.Write(ex.Message); } Server.ClearError(); 功能本地OK,发到服务器就不行,为什么= = subsitution控件,有什么作用? 一个封杀用户名的问题 使用连接检测用户名 在线等 没有装vs怎么解决这个问题? ODBC 驱动程序不支持所需的属性。 安装出现问题,求高手解决。 很奇怪的一个问题 导入WORD,生成在线调查的问题 请教一个问题 在点保存按扭后,页面刷新后,又回到页面的最前面,能否用JS进行定位,JS 页面定位的问题? httpwebrequest 自动登录后 IE浏览器自动跳转
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码
Response.Redirect("友好提示页面.html");
}
web.config怎么实现?看那个传送门内容没看懂。
webconfig.xml:
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="Error.aspx"/>
</system.web>
</configuration>Global.asax:
protected void Application_Error(object sender, EventArgs e)
{
try
{
Server.Transfer("Error.aspx");
}
catch { }
} Error.aspx:
Exception ex = Server.GetLastError().GetBaseException();
if (ex != null)
{
Response.Write(ex.Message);
}
Server.ClearError();