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

查看:26
本文介绍了如何在 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]
        }

[消息框显示错误]

谢谢

推荐答案

您无法在客户端计算机或服务器上合理地显示消息框.对于客户端的计算机,您需要重定向到带有适当错误消息的错误页面,如果需要,可能包括异常消息和堆栈跟踪.在服务器上,您可能希望对事件日志或日志文件进行一些日志记录.

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天全站免登陆