private void SetErrorPage(HttpStatusCode code, string pageType, IOwinContext context) { var type = ((pageType ?? WebPageType.Form.ToString()) == WebPageType.Modal.ToString() ? WebPageType.Modal : WebPageType.Form).ToString(); var pagePath = Config.ErrrorPagesBaseUrl + (int)code; if (code == HttpStatusCode.Unauthorized) { pagePath = Config.LoginUrl; } pagePath = ("/" + LanguageManager.ApplyLanguageAndMobileSignToAjaxRequestAsync (pagePath.Replace(Config.UrlDelimeter, Helper.RootUrl).Replace("#", ""))).Replace("//", "/"); IAspect aspect; AuthorizeManager.AuthorizeWebPageUrl(pagePath, type, out aspect); if (!aspect.HasMobileVersion) { pagePath = (pagePath + @"/").EndsWith(Config.MobileSign) ? pagePath.Replace(Config.MobileSign.Substring(0, Config.MobileSign.Length - 1), "").Replace("//", "/") : pagePath.Replace(Config.MobileSign, Helper.RootUrl).Replace("//", "/"); //pagePath = pagePath.Replace(Config.MobileSign, Helper.RootUrl); } pagePath = (Config.PagesPath.Substring(1) + pagePath.Replace("//", "/")).Replace("//", "/"); context.Response.Redirect(pagePath.Replace("//", "/") + "-" + type + ".json?url=" + pagePath.Replace(Config.PagesPath.Substring(1), Helper.RootUrl).Replace("//", "/") + "&type=" + type); }
public override async Task Invoke(IOwinContext context) { var mainPath = Config.DefaultsGetWebPagesServiceUrl.ToLower(); var isModal = false; var requestUrl = context.Request.Path.Value.ToLower(); if (requestUrl.StartsWith(mainPath) && !Settings.IsDebugMode) { var url = requestUrl.Replace(mainPath, ""); if (url.Length > 5) { if (url.Substring(url.Length - 5) == "/true") { url = url.Remove(url.Length - 5); isModal = true; } } var dbUrl = ("/" + LanguageManager.ApplyLanguageAndMobileSignToAjaxRequestAsync (url.Replace(Config.UrlDelimeter, Helper.RootUrl).Replace("#", ""))).Replace("//", "/"); var type = (isModal ? WebPageType.Modal : WebPageType.Form).ToString(); try { IAspect aspect; var isAuthorize = AuthorizeManager.AuthorizeWebPageUrl(dbUrl, type, out aspect); if (!isAuthorize) { SetErrorPage(HttpStatusCode.Unauthorized, type, context); } else if (aspect.IsNull) { SetErrorPage(HttpStatusCode.NotFound, type, context); } else { if (!aspect.HasMobileVersion && Config.MobileFallBack) { dbUrl = (dbUrl + @"/").EndsWith(Config.MobileSign) ? dbUrl.Replace(Config.MobileSign.Substring(0, Config.MobileSign.Length - 1), "").Replace("//", "/") : dbUrl.Replace(Config.MobileSign, Helper.RootUrl).Replace("//", "/"); //dbUrl = dbUrl.Replace(Config.MobileSign, Helper.RootUrl); } dbUrl = dbUrl.EndsWith("/") ? dbUrl.Substring(0, dbUrl.Length - 1) : dbUrl; url = (Config.PagesPath.Substring(1) + dbUrl.Replace("//", "/")).Replace("//", "/"); context.Response.Redirect(url + "-" + (isModal ? WebPageType.Modal : WebPageType.Form) + ".json?url=" + dbUrl.Replace("//", "/") + "&type=" + (isModal ? WebPageType.Modal : WebPageType.Form)); } } catch (Exception ex) { SetErrorPage(HttpStatusCode.NotFound, type, context); _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); } } await Next.Invoke(context); }
private void SetErrorPage(HttpStatusCode code, string pageType) { try { _context.Response.StatusCode = (int)code; var type = ((pageType ?? WebPageType.Form.ToString()) == WebPageType.Modal.ToString() ? WebPageType.Modal : WebPageType.Form); var pagePath = Config.ErrrorPagesBaseUrl + (int)code; if (code == HttpStatusCode.Unauthorized) { pagePath = Config.LoginUrl; } var virtualPath = pagePath + "-" + type + ".json"; var path = (Config.PagesPath + Settings.Language + virtualPath).Replace("//", "/"); if (Settings.IsMobileMode) { IAspect aspect; AuthorizeManager.AuthorizeWebPageUrl(pagePath, type.ToString(), out aspect); if (aspect.HasMobileVersion) path = (Config.PagesPath + Settings.Language + Config.MobileSign + virtualPath).Replace("//", "/"); } _context.Response.WriteFile(path.Replace("~", "")); } catch (Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); _context.Response.ContentType = "application/json"; _context.Response.Write((JObject.Parse(JsonConvert.SerializeObject (new { modifyRoleId = 5, viewRoleId = 6, enableCache = false, status = 1, title = "Error!", cacheSlidingExpirationTimeInMinutes = 0, pageId = "if29a53784fb34da1806c6ce945790dc5", dependentModules = "[]", param = "{}", html = " <span style='display:none' id='if29a53784fb34da1806c6ce945790dc5'></span>Error!" }, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))).ToString()); } }
private void StartAsyncTask(Object workItemState) { var queryString = _context.Request.QueryString; var url = queryString["url"]; var type = queryString["type"]; try { if (url == null || type == null) { SetErrorPage(HttpStatusCode.Unauthorized, type); } else { IAspect aspect; if (AuthorizeManager.AuthorizeWebPageUrl(url, type, out aspect) || url.Contains(Config.ErrrorPagesBaseUrl.Substring(1))) { if (aspect.Status == 0) SetErrorPage(HttpStatusCode.TemporaryRedirect, type); else { if (aspect.EnableCache) { var pageType = type == WebPageType.Modal.ToString() ? WebPageType.Modal : WebPageType.Form; if (!aspect.HasMobileVersion && Config.MobileFallBack) { url = (url + @"/").EndsWith(Config.MobileSign) ? url.Replace(Config.MobileSign.Substring(0, Config.MobileSign.Length - 1), "").Replace("//", "/") : url.Replace(Config.MobileSign, Helper.RootUrl).Replace("//", "/"); //url = url.Replace(Config.MobileSign, Helper.RootUrl); } var key = CacheManager.GetWebPageKey(pageType.ToString(), url); var pageCache = CacheManager.Get<dynamic>(key); if (!pageCache.IsCached) { CacheManager.Store(key, _dataBaseContextManager.GetWebPageForView(url, type).ToJObject(), slidingExpiration: TimeSpan.FromMinutes(aspect.CacheSlidingExpirationTimeInMinutes)); pageCache = CacheManager.Get<dynamic>(key); } _context.Response.Write(pageCache.Value.ToString()); } else { var path = _context.Request.RawUrl.IndexOf("?", StringComparison.Ordinal) > 0 ? _context.Request.RawUrl.Remove(_context.Request.RawUrl.IndexOf("?", StringComparison.Ordinal)) : _context.Request.RawUrl; if (!aspect.HasMobileVersion && Config.MobileFallBack) { path = (path + @"/").EndsWith(Config.MobileSign) ? path.Replace(Config.MobileSign.Substring(0, Config.MobileSign.Length - 1), "").Replace("//", "/") : path.Replace(Config.MobileSign, Helper.RootUrl).Replace("//", "/"); //path = path.Replace(Config.MobileSign, Helper.RootUrl); } _context.Response.WriteFile(path); } } } else { SetErrorPage(HttpStatusCode.Unauthorized, type); } } } catch (Exception ex) { SetErrorPage(HttpStatusCode.NotFound, type); _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); } _completed = true; _callback(this); }