当前位置: 首页>>代码示例>>C#>>正文


C# HttpContextBase.ClearError方法代码示例

本文整理汇总了C#中System.Web.HttpContextBase.ClearError方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.ClearError方法的具体用法?C# HttpContextBase.ClearError怎么用?C# HttpContextBase.ClearError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpContextBase的用法示例。


在下文中一共展示了HttpContextBase.ClearError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClearHttpContext

 private void ClearHttpContext(HttpContextBase context, int statusCode)
 {
     context.Response.StatusCode = statusCode;
     context.ClearError();
     context.Response.Clear();
     context.Response.TrySkipIisCustomErrors = true;
 }
开发者ID:TkachukOrest,项目名称:Catch-Me-If-You-Can,代码行数:7,代码来源:MvcErrorHandler.cs

示例2: HandleError

        public void HandleError(HttpContextBase context, int statusCode)
        {
            var currentError = context.Error;

            if (currentError.IsNull()) return;

            #if DEBUG
            Debugger.Break();
            #endif

            this.LogException(currentError);

            if (!context.IsCustomErrorEnabled || !UseCustomErrors(context.Request.IsLocal)) return;

            var httpException = currentError as HttpException;
            if (httpException != null) statusCode = httpException.GetHttpCode();

            context.Response.SetStatus(statusCode);

            _errorViewRenderer.Render(context, statusCode, currentError);

            context.ClearError();

            context.Response.TrySkipIisCustomErrors = true;
        }
开发者ID:alanstevens,项目名称:Contrive,代码行数:25,代码来源:HttpErrorHandler.cs

示例3: OnError

        public override void OnError(HttpContextBase context)
        {
            Exception e = context.Server.GetLastError().GetBaseException();
            HttpException httpException = e as HttpException;
            int statusCode = (int)HttpStatusCode.InternalServerError;

            if (httpException != null)
            {
                statusCode = httpException.GetHttpCode();
            }

            ILog log;

            if (!Ioc.TryGet(out log))
            {
                log = new NullLogger();
            }

            if (httpException != null)
            {
                switch (statusCode)
                {
                    case (int)HttpStatusCode.NotFound:
                        log.Warning(this, "Http Error: `{0}`, Request path: `{1}`", statusCode, context.Request.AppRelativeCurrentExecutionFilePath);
                        break;
                    default:
                        log.Error(this, "Http Error: `{0}`, Request path: `{1}`", statusCode, context.Request.AppRelativeCurrentExecutionFilePath);
                        break;
                }
            }
            else
            {
                log.Error(this, "Web application error: `{0}`, Request path: `{1}`", e, context.Request.AppRelativeCurrentExecutionFilePath);
            }

            string redirectUrl = null;

            if (context.IsCustomErrorEnabled)
            {
                CustomErrorsSection section = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors");

                if (section != null)
                {
                    redirectUrl = section.DefaultRedirect;

                    if (httpException != null)
                    {
                        if (section.Errors.Count > 0)
                        {
                            CustomError item = section.Errors[statusCode.ToString()];

                            if (item != null)
                            {
                                redirectUrl = item.Redirect;
                            }
                        }
                    }
                }

                context.Response.Clear();
                context.Response.StatusCode = statusCode;
                context.Response.TrySkipIisCustomErrors = true;

                context.ClearError();

                if (!redirectUrl.IsNullOrEmpty())
                {
                    //context.Response.Redirect(redirectUrl);
                    context.Server.Transfer(redirectUrl);
                }
            }
        }
开发者ID:pleb,项目名称:Chillow,代码行数:72,代码来源:ErrorHandler.cs


注:本文中的System.Web.HttpContextBase.ClearError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。