如何显示在Web应用程序asp.net C#一个错误消息框 [英] How to display an error message box in a web application asp.net c#

查看:311
本文介绍了如何显示在Web应用程序asp.net C#一个错误消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET Web应用程序,我想知道当一个异常被抛出我如何能显示一个错误消息框。

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.

例如,

        try
        {
            do something
        }
        catch 
        {
            messagebox.write("error"); 
            //[This isn't the correct syntax, just what I want to achieve]
        }

[消息框显示了错误]

[The message box shows the error]

感谢您

推荐答案

您不能合理地显示客户端的计算机或服务器上的一个消息框,无论是。对于客户端的计算机,你要重定向到一个错误页面显示相应的错误信息,可能包括如果你想要异常消息和堆栈跟踪。在服务器上,你可能会想要做一些记录,或者到事件日志或日志文件。

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 );
 }

请注意,日志上面必须由你来实现,可能使用log4net的或其他一些记录工具。

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

这篇关于如何显示在Web应用程序asp.net C#一个错误消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆