locked
Need real error message RRS feed

  • Question

  • User546194788 posted

    To display general error message I added the following code in web.config as below in which will display a message:

    <customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/GeneralErrorPage.htm" />

    Order apps is not available now. Please check it later

    I want to disable these code and get real error message.

    Is there any to have apps send me (e.g. Email me) the real error like web server event viewer?

    Wednesday, July 10, 2019 5:36 PM

Answers

All replies

  • User409696431 posted

    Refer to https://imar.spaanjaars.com/268/how-do-i-handle-errors-and-send-an-error-notification-from-aspnet-applications

    It describes adding code to Gobal.aspx's code behind page to catch errors and email them to you.  You still show the friendly error page to your site visitors.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 10, 2019 11:38 PM
  • User-1174608757 posted

    Hi aspfun,

    According to your description, I suggest you could write you logic in application_ error method in Gloab.asax and then you could catch the detail about error  and  send an  email about error message.

    You could write as below:

     void Application_Error(object sender, EventArgs e)
            {
                Exception objErr = Server.GetLastError().GetBaseException();
                string err = "<br><b>Error in: </b>" + Request.Url.ToString() +
                    "<br><b>Error Message: </b>" + objErr.Message.ToString() +
                    "<br><b>Stack Trace:</b><br>" + objErr.StackTrace.ToString();
                //Email sending method
                Email.Send("example@gmail.com", "Error", err, true);
            }

    Here is the link I hope it could help you.

    https://stackoverflow.com/questions/11807891/how-to-send-error-info-mail-if-any-error-occurred-in-web-application

    Best Regards

    Wei

    Thursday, July 11, 2019 1:55 AM
  • User546194788 posted

    Hi Wei Zhang, 

    I used your way and open the link.

    But, the system error display as below instead of email.

    Server Error in '/' Application.


    Configuration Error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Could not load file or assembly 'XXXXXXX'

    Source Error:

    ...........................................

    Thursday, July 11, 2019 12:51 PM
  • User546194788 posted

    I follow the link below and added code.

    https://stackoverflow.com/questions/11807891/how-to-send-error-info-mail-if-any-error-occurred-in-web-application

    void Application_Error(object sender, EventArgs e) 
        {
            Exception objErr = Server.GetLastError().GetBaseException();
            string err = "<br><b>Error in: </b>" + Request.Url.ToString() +
                "<br><b>Error Message: </b>" + objErr.Message.ToString() +
                "<br><b>Stack Trace:</b><br>" + objErr.StackTrace.ToString();
           //Email sending method
           Email.Send("example@gmail.com", "Error", err, true);
        }

    Web.config:

    <customErrors mode="Off" defaultRedirect="Customerrorpage.aspx">
          <error statusCode="404" redirect="Error404.aspx" />
    </customErrors>

    Customerrorpage.aspx : (Auto redirect to login page in few sec)

    protected void Page_Load(object sender, EventArgs e)
        {
            Response.AppendHeader("Refresh", "4; url=Login.aspx");
        }
    Thursday, July 11, 2019 12:54 PM
  • User546194788 posted

    I tried KathW's way, it works great!

    Thank you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 11, 2019 2:34 PM
  • User546194788 posted

    I followed KathyW's way from the link below to add error tracking. It works fine but did not indicate the line of code.

    Here is the error is caught but I still don't know which code to cause it.

    Message

    Invalid length for a Base-64 char array.

    Source

    mscorlib

    Target site

    Byte[] FromBase64String(System.String)

     

    Stack trace

       at System.Convert.FromBase64String(String s)

       at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

       at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)

       at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState)

       at System.Web.UI.HiddenFieldPageStatePersister.Load()

     

    ToString()

    System.FormatException: Invalid length for a Base-64 char array.

       at System.Convert.FromBase64String(String s)

       at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

       at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)

       at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState)

       at System.Web.UI.HiddenFieldPageStatePersister.Load()

    Thursday, August 8, 2019 6:29 PM