示例#1
0
 private static Task ProcessException(HttpContext context, WebDefaultXmlConfig defaultConfig,
                                      WebBasePage page, PageSourceInfo info, Exception exception)
 {
     if (exception is RedirectException redirectEx)
     {
         context.Response.Redirect(redirectEx.Url.ToString(), false);
         return(Task.FromResult(0));
     }
     else if (exception is ReLogOnException)
     {
         return(HandleException(defaultConfig.ReLogOnHandler,
                                GetWebHandler(page, context, info), page, exception));
     }
     else if (exception is ErrorPageException)
     {
         return(HandleException(defaultConfig.ErrorPageHandler,
                                GetWebHandler(page, context, info), page, exception));
     }
     else if (exception is ErrorOperationException)
     {
         return(HandleException(defaultConfig.ErrorOperationHandler,
                                GetWebHandler(page, context, info), page, exception));
     }
     else if (exception is ToolkitException)
     {
         return(HandleException(defaultConfig.ToolkitHandler,
                                GetWebHandler(page, context, info), page, exception));
     }
     else
     {
         return(HandleException(defaultConfig.ExceptionHandler,
                                GetWebHandler(page, context, info), page, exception));
     }
 }
示例#2
0
        private static Task HandleException(IConfigCreator <IExceptionHandler> exceptionHandler,
                                            IWebHandler handler, WebBasePage page, Exception ex)
        {
            IPageData         pageData  = page ?? handler;
            IExceptionHandler exHandler = exceptionHandler.CreateObject(pageData);

            return(exHandler.HandleException(handler, page, ex));
        }
        public Task HandleException(IWebHandler handler, WebBasePage page, Exception ex)
        {
            TkDebug.AssertArgument(ex is ErrorPageException, "ex", string.Format(ObjectUtil.SysCulture,
                                                                                 "此Handler只处理ErrorPageException,当前的Exception类型为{0}", ex.GetType()), this);

            ErrorPageSource source = new ErrorPageSource((ErrorPageException)ex);

            return(InternalWebUtil.WritePage(null, source, fPageMaker, handler));
        }
示例#4
0
        public Task HandleException(IWebHandler handler, WebBasePage page, Exception ex)
        {
            FileData data = FileData.Create(fFileName);

            if (LogException)
            {
                string type = page == null?handler.GetType().ToString() : page.GetType().ToString();

                ExceptionData exData = new ExceptionData(handler.SourceInfo.Source,
                                                         type, handler.PageUrl.ToString(), ex);
                ExceptionUtil.LogException(exData);
            }
            handler.Response.ContentType = ContentTypeConst.HTML;
            return(handler.Response.WriteAsync(Encoding.UTF8.GetString(data.Data), Encoding.UTF8));
        }
        public Task HandleException(IWebHandler handler, WebBasePage page, Exception ex)
        {
            string type = page == null?handler.GetType().ToString() : page.GetType().ToString();

            ExceptionSource source = new ExceptionSource(handler.SourceInfo.Source,
                                                         type, handler.PageUrl.ToString(), ex);

            if (LogException || handler.IsPost)
            {
                string fileName = ExceptionUtil.LogException(source.Data);
                source.FileName = fileName;
            }

            return(InternalWebUtil.WritePage(null, source, fPageMaker, handler));
        }
        public Task HandleException(IWebHandler handler, WebBasePage page, Exception ex)
        {
            TkDebug.AssertArgument(ex is ReLogOnException, "ex", string.Format(ObjectUtil.SysCulture,
                                                                               "此Handler只处理ReLogonException,当前的Exception类型为{0}", ex.GetType()), this);
            TkDebug.ThrowIfNoAppSetting();

            string     logOnUrl = WebAppSetting.WebCurrent.LogOnPath;
            UriBuilder builder  = new UriBuilder(logOnUrl);
            string     retUrl   = "RetUrl=" + HttpUtility.UrlEncode(ex.Message);

            if (builder.Query != null && builder.Query.Length > 1)
            {
                builder.Query = builder.Query.Substring(1) + "&" + retUrl;
            }
            else
            {
                builder.Query = retUrl;
            }
            handler.Response.Redirect(builder.Uri.ToString(), false);

            return(Task.FromResult(0));
        }
示例#7
0
 public abstract Task HandleException(IWebHandler handler, WebBasePage page, Exception ex);
 public Task HandleException(IWebHandler handler, WebBasePage page, Exception ex)
 {
     throw new Exception("空Exception,具体请看InnerException", ex);
 }
示例#9
0
        public Task ProcessRequest(HttpContext context, RequestDelegate next, PathStringParser parser)
        {
            PageSourceInfo info = null;

            parser.Parse((input) =>
            {
                info = ParseUrl(input, info);
            });
            if (info == null)
            {
                return(null);
            }

            context.Items[WebUtil.SOURCE_INFO] = info;

            WebDefaultXmlConfig defaultConfig = WebGlobalVariable.WebCurrent.WebDefaultValue;
            WebBasePage         page          = null;

            try
            {
                if (info.IsContent)
                {
                    page = new WebModuleContentPage(context, next, info);
                }
                else
                {
                    page = new WebModuleRedirectPage(context, next, info);
                }
                return(page.LoadPage());
            }
            catch (RedirectException ex)
            {
                context.Response.Redirect(ex.Url.ToString(), false);
                return(Task.FromResult(0));
            }
            catch (ReLogOnException ex)
            {
                return(HandleException(defaultConfig.ReLogOnHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (ErrorPageException ex)
            {
                return(HandleException(defaultConfig.ErrorPageHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (ErrorOperationException ex)
            {
                return(HandleException(defaultConfig.ErrorOperationHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (ToolkitException ex)
            {
                return(HandleException(defaultConfig.ToolkitHandler,
                                       GetWebHandler(page, context, info), page, ex));
            }
            catch (Exception ex)
            {
                Exception innerEx = ex.InnerException;
                if (innerEx != null)
                {
                    return(ProcessException(context, defaultConfig, page, info, innerEx));
                }
                else
                {
                    return(ProcessException(context, defaultConfig, page, info, ex));
                }
            }
        }
示例#10
0
 public HomePage OpenHomePage()
 {
     WebDriver.Navigate().GoToUrl(TestWebsiteUrl);
     return(WebBasePage.GetInstance <HomePage>(WebDriver));
 }