WEB.CONFIG可配置 了404自定义错误页后,如何使网站下所有文件在访问不到时都会跳转呢?
2个回答
2013-04-06
展开全部
需要配置Global.asax 文件global.asax 下有一个Application_Error 具体内容: Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' 发生错误时激发
''在出现未处理的错误时运行的代码 Dim erroy As Exception = Server.GetLastError() Dim err As String = "出错页面是:" & Request.Url.ToString() & "</br>" err += "异常信息:" + erroy.Message & "</br>" err += "Source:" + erroy.Source & "</br>" err += "StackTrace:" + erroy.StackTrace & "</br>" ''清除前一个异常 Server.ClearError() ''此处理用Session["ProError"]出错。所以用 Application["ProError"] Application("erroy") = err ''此处不是page中,不能用Response.Redirect("../frmSysError.aspx");
Dim url As String = "http://" + Request.ServerVariables("HTTP_HOST").ToString + "/" System.Web.HttpContext.Current.Response.Redirect(url + "error404.aspx")
End Sub
error404.aspx 显示错误的页面 该页面需写 LOAD事件 '显示程序中的错误码 If Application("erroy") IsNot Nothing Then Dim err As String = Application("erroy").ToString
errorss.InnerHtml = err end ifLOAD的事件写完后 将下面复制 黏贴到显示 错误的页面 Private Sub DealErroy()
Dim erroy As New HttpException()
Dim strCode As String = erroy.ErrorCode.ToString()
Dim strMsg As String = erroy.Message
erroy.HelpLink = "sss"
Response.Write("ErrorCode:" & strCode & "< br>")
Response.Write("Message:" & strMsg & "< br>")
Response.Write("HelpLink:" & erroy.HelpLink & "< br>")
Response.Write("Source:" & erroy.Source & "< br>")
'Response.Write("TargetSite:" + erroy.TargetSite & "< br>")
'Response.Write("InnerException:" + erroy.InnerException & "< br>")
Response.Write("StackTrace:" + erroy.StackTrace & "< br>")
Response.Write("GetHtmlErrorMessage:" & erroy.GetHtmlErrorMessage() & "< br>")
Response.Write("erroy.GetHttpCode().ToString():" & erroy.GetHttpCode().ToString() & "< br>")
Response.Write("erroy.Data.ToString()::" & erroy.Data.ToString() & "< br>")
End Sub errorss 是在设计模式下 增加一个 <div id=errorss runat=server></div> web.config 下 <!--
<customErrors mode="On" defaultRedirect="error404.aspx">
<error statusCode="403" redirect="404.aspx"/>
<error statusCode="404" redirect="404.aspx"/>
<error statusCode="500" redirect="404.aspx"/>
</customErrors>
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
' 发生错误时激发
''在出现未处理的错误时运行的代码 Dim erroy As Exception = Server.GetLastError() Dim err As String = "出错页面是:" & Request.Url.ToString() & "</br>" err += "异常信息:" + erroy.Message & "</br>" err += "Source:" + erroy.Source & "</br>" err += "StackTrace:" + erroy.StackTrace & "</br>" ''清除前一个异常 Server.ClearError() ''此处理用Session["ProError"]出错。所以用 Application["ProError"] Application("erroy") = err ''此处不是page中,不能用Response.Redirect("../frmSysError.aspx");
Dim url As String = "http://" + Request.ServerVariables("HTTP_HOST").ToString + "/" System.Web.HttpContext.Current.Response.Redirect(url + "error404.aspx")
End Sub
error404.aspx 显示错误的页面 该页面需写 LOAD事件 '显示程序中的错误码 If Application("erroy") IsNot Nothing Then Dim err As String = Application("erroy").ToString
errorss.InnerHtml = err end ifLOAD的事件写完后 将下面复制 黏贴到显示 错误的页面 Private Sub DealErroy()
Dim erroy As New HttpException()
Dim strCode As String = erroy.ErrorCode.ToString()
Dim strMsg As String = erroy.Message
erroy.HelpLink = "sss"
Response.Write("ErrorCode:" & strCode & "< br>")
Response.Write("Message:" & strMsg & "< br>")
Response.Write("HelpLink:" & erroy.HelpLink & "< br>")
Response.Write("Source:" & erroy.Source & "< br>")
'Response.Write("TargetSite:" + erroy.TargetSite & "< br>")
'Response.Write("InnerException:" + erroy.InnerException & "< br>")
Response.Write("StackTrace:" + erroy.StackTrace & "< br>")
Response.Write("GetHtmlErrorMessage:" & erroy.GetHtmlErrorMessage() & "< br>")
Response.Write("erroy.GetHttpCode().ToString():" & erroy.GetHttpCode().ToString() & "< br>")
Response.Write("erroy.Data.ToString()::" & erroy.Data.ToString() & "< br>")
End Sub errorss 是在设计模式下 增加一个 <div id=errorss runat=server></div> web.config 下 <!--
<customErrors mode="On" defaultRedirect="error404.aspx">
<error statusCode="403" redirect="404.aspx"/>
<error statusCode="404" redirect="404.aspx"/>
<error statusCode="500" redirect="404.aspx"/>
</customErrors>
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询