加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.Net Response.Redirect不能在Application_Error中工作?

发布时间:2020-12-15 22:19:16 所属栏目:asp.Net 来源:网络整理
导读:我不知道为什么当我将代码部署到IIS7时,Response.Redirect不能正常工作?白/黄错误页面总是显示,而不是我的错误.但是当我的计算机上使用Visual Studio进行调试运行时,它运行正常吗? protected void Application_Error(object sender,EventArgs e) { ILog lo
我不知道为什么当我将代码部署到IIS7时,Response.Redirect不能正常工作?白/黄错误页面总是显示,而不是我的错误.但是当我的计算机上使用Visual Studio进行调试运行时,它运行正常吗?
protected void Application_Error(object sender,EventArgs e)
        {
            ILog log = LogManager.GetLogger(typeof(Global).Name);
            Exception objErr = Server.GetLastError().GetBaseException();
            log.Error(objErr);
            string err = "Error Caught in Application_Error eventn" +
                    "nError Message:" + objErr.Message.ToString() +
                    "nStack Trace:" + objErr.StackTrace.ToString();
            EventLog.WriteEntry("Kiosk",err,EventLogEntryType.Error);
            Server.ClearError();
            Response.Redirect("~/Error.aspx",false);
        }

解决方法

我有同样的问题,并解决了:
HttpContext.Current.ClearError();             
Response.Redirect("~/Error.aspx",false);
return;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读