本文介绍了WebConfig中的CustomErrors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中出现错误页面引发异常.我正在WebConfig中使用CustomErrors重定向到错误页面.我从异常中获取错误消息,但未重定向到我的错误页面..请帮助我. .


问候
B.Amuthan

Iam Having Error IN My Page The page Throws The Exception.I am Using CustomErrors In WebConfig For Redirecting To Error page.I am Getting Error Message From Exception but It Is Not Redirecting To My Error page..Pls Help Me...


Regards
B.Amuthan

推荐答案

<customerrors>
       mode="RemoteOnly" 
       defaultRedirect="~/errors/GeneralError.aspx" /></customerrors>





您可以通过在Global.asax文件中添加以下代码来实现相同的目的.
这很简单,很容易解释





The same you can achieve by adding below code in Global.asax file.
It is simple and self explanatory

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        '' Code that runs when an unhandled error occurs
        Dim ctx As HttpContext = HttpContext.Current
        Dim exception As Exception = ctx.Server.GetLastError
        Dim errInfo As String = "<br>Error In : " & ctx.Request.Url.ToString() & _
        "<br>Source:" & exception.Source & _
        "<br>Message: " & exception.Message
        '"<br>Stack Trace: " & exception.StackTrace 
        ctx.Response.Write(errInfo)
        'To let the page finish running we clear the error
        ctx.Server.ClearError()
        Session("value") = errInfo
'GenericError is the page where i am redirecting user with message
        System.Web.HttpContext.Current.Response.Redirect("~/GenericError.aspx")
    End Sub</br></br></br></br>



我通常更喜欢第二种选择,因为您可以在需要时获得错误的完整详细信息.

快乐编码

代码已格式化



I normally prefer 2nd option because you get the complete details of errors when required.

Happy Coding

Code has been Formatted




这篇关于WebConfig中的CustomErrors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:33