Ext.Net如何记录系统异常啊?

狼王_ 2014-01-23 02:28:51
用过Ext.Net的都知道当系统出错时Ext.Net框架会弹出一个框,如下:

我现在想做一个错误日志记录系统,我在Global.ascx中的捕获异常
protected void Application_Error(object sender, EventArgs e)
{
if (ConfigurationManager.AppSettings["LogSwitch"] == "on")
{
Exception ex = Server.GetLastError();
Exception iex = ex.InnerException;
string URL = Request.RawUrl;
string errormsg = string.Empty;
if (iex != null)
{
errormsg = iex.Message + "-----" + iex.StackTrace;
}
else
{
errormsg = ex.Message + "-----" + ex.StackTrace;
}
Server.Transfer("~/Error.aspx?msg=" + errormsg + "&url="+URL, false);
}
}

但是,Ext.Net框架有一套自己的捕获异常的机制,它会在出现异常时弹出如上图所示的窗口。有没有办法干掉这个窗口,让系统出错时跳转到Error.aspx页面啊?
...全文
212 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hj220800301 2014-10-24
  • 打赏
  • 举报
回复
我目前系统使用的完整的Pagebase类也贴出来供你参考。 + using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Threading; using System.Globalization; using Ext.Net; /// <summary> ///PageBase 的摘要说明 /// </summary> namespace Localization { public class PageBase : System.Web.UI.Page { protected override void InitializeCulture() { //base.InitializeCulture(); string UserCulture = ""; try { if (Session["PreferredCulture"] == null) Session["PreferredCulture"] = Request.UserLanguages[0]; } catch { Session["PreferredCulture"] = "en-us"; } if (Session["PreferredCulture"].ToString().ToUpper() == "ZH-CN" || Session["PreferredCulture"].ToString().ToUpper() == "EN-US") UserCulture = Session["PreferredCulture"].ToString(); else { Session["PreferredCulture"] = "en-us"; UserCulture = Session["PreferredCulture"].ToString(); } if (UserCulture != "") { Thread.CurrentThread.CurrentUICulture = new CultureInfo(UserCulture); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(UserCulture); } } protected override void OnPreLoad(EventArgs e) { base.OnPreLoad(e); if (!X.IsAjaxRequest) { if (Session["LoginUser"] == null) { //Response.Redirect("http://172.20.1.52/itsd/"); X.Msg.Alert(Resources.Global.SystemAlert, Resources.Global.LogAlert, "window.location.href='LogoutMes.aspx?srcgo=1'").Show(); //系统登录超时,请重新登录 return; } X.ResourceManager.ShowWarningOnAjaxFailure = false; X.ResourceManager.Listeners.AjaxRequestException.Handler = "Ext.net.DirectMethods.WriteError(arguments[1].errorMessage)"; } } protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); if (Session["LoginUser"] == null) { X.Msg.Alert(Resources.Global.SystemAlert, Resources.Global.LogAlert, "window.location.href='LogoutMes.aspx?srcgo=1'").Show(); //Response.Redirect("http://172.20.1.52/itsd/"); return; } } override protected void OnInit(EventArgs e) { base.OnInit(e); if (Session["LoginUser"] == null) { HttpCookie cookieName = Request.Cookies["LoginName"]; HttpCookie cookieDomain = Request.Cookies["LoginDomain"]; if (cookieName != null | cookieDomain != null) { cookieName.Expires = DateTime.Now.AddDays(-10); cookieDomain.Expires = DateTime.Now.AddDays(-10); } //Response.Redirect("http://172.20.1.52/itsd/"); X.Msg.Alert(Resources.Global.SystemAlert, Resources.Global.LogAlert, "window.location.href='LogoutMes.aspx?srcgo=1'").Show(); //系统登录超时,请重新登录 return; } } protected void Page_Error(object sender, System.EventArgs e) { try { Exception error = Server.GetLastError(); Exception bjErr = Server.GetLastError().GetBaseException(); string msg = Resources.Global.ErrorPage + Request.Url.ToString() + Resources.Global.ErrorMsg + error.Message + Resources.Global.Date + DateTime.Now.ToString(); Server.ClearError(); Response.Redirect("~/Error.aspx?ErrorFlag=OtherError"); } catch { Response.Redirect("~/Error.aspx?ErrorFlag=OtherError"); } } protected void Application_Error(object sender, System.EventArgs e) { try { Exception error = Server.GetLastError(); Exception bjErr = Server.GetLastError().GetBaseException(); string msg = Resources.Global.ErrorPage + Request.Url.ToString() + Resources.Global.ErrorMsg + error.Message + Resources.Global.Date + DateTime.Now.ToString(); Server.ClearError(); Response.Redirect("~/Error.aspx?ErrorFlag=OtherError"); } catch { Response.Redirect("~/Error.aspx?ErrorFlag=OtherError"); } } [DirectMethod] public void WriteError(string msg) { Response.Redirect("~/Error.aspx?ErrorFlag=‘“+msg+”’"); //ExceptionPolicy.HandleException(new Exception(msg), "GlobalException"); //Server.ClearError(); //#if DEBUG // // Console.WriteLine(Server.GetLastError().Message); //#else // Response.Redirect("~/Error.aspx"); //#endif // Response.Redirect("~/Error.aspx"); } } }
hj220800301 2014-10-24
  • 打赏
  • 举报
回复
http://www.cnblogs.com/tuncaysanli/p/3194526.html 这个地址的做法可行,只是你没有正确的复制他的方法。 首先你要先建个base.cs 类 namespace Localization { public class PageBase : System.Web.UI.Page { ..... 在这个类中重写PreLoad方法 protected override void OnPreLoad(EventArgs e) { base.OnPreLoad(e); if (!X.IsAjaxRequest) { if (Session["LoginUser"] == null) { //Response.Redirect("http://172.20.1.52/itsd/"); X.Msg.Alert(Resources.Global.SystemAlert, Resources.Global.LogAlert, "window.location.href='LogoutMes.aspx?srcgo=1'").Show(); //系统登录超时,请重新登录 return; } X.ResourceManager.ShowWarningOnAjaxFailure = false; X.ResourceManager.Listeners.AjaxRequestException.Handler = "Ext.net.DirectMethods.WriteError(arguments[1].errorMessage)"; } } 然后写个WriteError方法供上面调用就可以了 [DirectMethod] public void WriteError(string msg) { Response.Redirect("~/Error.aspx?ErrorFlag=‘“+msg+”’"); //ExceptionPolicy.HandleException(new Exception(msg), "GlobalException"); //Server.ClearError(); //#if DEBUG // // Console.WriteLine(Server.GetLastError().Message); //#else // Response.Redirect("~/Error.aspx"); //#endif // Response.Redirect("~/Error.aspx"); }
t101lian 2014-01-23
  • 打赏
  • 举报
回复

        protected void Application_Error(object sender, EventArgs e)
        {
            Response.Redirect("~/error.aspx");
        }
你先试试上面的不传msg=" + errormsg + "&url="+URL,报错直接就跳转还会有那个窗口吗?
md5e 2014-01-23
  • 打赏
  • 举报
回复
#region 覆盖系统默认的错误页 protected override void OnError(EventArgs e) { HttpContext ctx = HttpContext.Current; Exception exception = ctx.Server.GetLastError(); if (SiteSystem.isLog == 1) { log.Error("访问页面出错,页面地址:" + ctx.Request.Url.AbsoluteUri, exception); } if (!ctx.Request.RawUrl.ToLower().Contains("error.aspx")) { string _url = (SiteSystem.ErrorUrl == "" ? "/error.aspx" : SiteSystem.ErrorUrl) + "?error=" + ctx.Server.UrlEncode(exception.Message) + "&returcode=" + ctx.Server.UrlEncode(ctx.Request.RawUrl); ctx.Response.Redirect(_url, true); } ctx.Response.Redirect(SiteSystem.ErrorUrl == "" ? "/error.htm" : SiteSystem.ErrorUrl, true); } #endregion
狼王_ 2014-01-23
  • 打赏
  • 举报
回复
这是我在网上看到的一篇文章,但是我按照他说的做,并没有实现效果,哪位有这方面的经验啊?? http://www.cnblogs.com/tuncaysanli/p/3194526.html

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧