How to display an error message box in a web application asp.net c#

后端 未结 7 1383
小蘑菇
小蘑菇 2020-12-03 18:28

I have an ASP.NET web application, and I wanted to know how I could display an error message box when an exception is thrown.

For example,

                 


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 19:05

    You can't reasonably display a message box either on the client's computer or the server. For the client's computer, you'll want to redirect to an error page with an appropriate error message, perhaps including the exception message and stack trace if you want. On the server, you'll probably want to do some logging, either to the event log or to a log file.

     try
     {
         ....
     }
     catch (Exception ex)
     {
         this.Session["exceptionMessage"] = ex.Message;
         Response.Redirect( "ErrorDisplay.aspx" );
         log.Write( ex.Message  + ex.StackTrace );
     }
    

    Note that the "log" above would have to be implemented by you, perhaps using log4net or some other logging utility.

提交回复
热议问题