public Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken) { try { var serviceUrl = actionContext.Request.RequestUri.AbsolutePath; var key = CacheManager.GetAspectKey(CacheKey.Aspect.ToString(), ActionKey.RequestService.ToString(), serviceUrl); IAspect aspect; if (CacheManager.Get <IAspect>(key).IsCached) { aspect = CacheManager.Get <IAspect>(key).Value; } else { aspect = _dataBaseContextManager.GetAspectForPublicMasterDataKeyValueUrl(serviceUrl); CacheManager.Store(key, aspect, slidingExpiration: TimeSpan.FromMinutes(Config.AspectCacheSlidingExpirationTimeInMinutes)); } if (aspect.EnableLog) { // var actionLogManager = actionContext.Request.GetDependencyScope() //.GetService(typeof(Log.Base.IActionLogManager)) as Log.Base.IActionLogManager; _actionLogManager?.LogOdataService(aspect.Name, actionContext.Request); } } catch (Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); } return(Task.FromResult(0)); }
public override int SaveChanges() { FillLogProperty(); try { return(base.SaveChanges()); } catch (DbUpdateConcurrencyException) { //var entry = ex.Entries.Single(); ////The MSDN examples use Single so I think there will be only one ////but if you prefer - do it for all entries ////foreach(var entry in ex.Entries) ////{ //if (entry.State == EntityState.Deleted) // //When EF deletes an item its state is set to Detached // //http://msdn.microsoft.com/en-us/data/jj592676.aspx // entry.State = EntityState.Detached; //else // entry.OriginalValues.SetValues(entry.GetDatabaseValues()); ////throw; //You may prefer not to resolve when updating ////} throw new DataConcurrencyException(); } catch (DbEntityValidationException ex) { var errors = new List <KeyValue>(); foreach (var dbValidationErrors in ex.EntityValidationErrors.Select(er => er.ValidationErrors)) { errors.AddRange(dbValidationErrors.Select(dbValidationError => new KeyValue() { Key = dbValidationError.PropertyName, Value = dbValidationError.ErrorMessage })); } ErrorLogManager.LogException(new ExceptionLog() { Detail = string.Join(" - ", errors.Select(er => er.Key + " : " + er.Value)), Message = ex.Message, Source = ex.GetType().FullName }); throw; } }
public override async Task Invoke(IOwinContext context) { var specialService = ""; if (_specialServices.Any(service => context.Request.Path.Value == service)) { specialService = context.Request.Path.Value; } try { if (specialService != "") { IAspect aspect; var key = CacheManager.GetAspectKey(CacheKey.Aspect.ToString(), ActionKey.RequestService.ToString(), specialService); if (CacheManager.Get <IAspect>(key).IsCached) { aspect = CacheManager.Get <IAspect>(key).Value; } else { aspect = _dataBaseContextManager.GetAspectForPublicMasterDataKeyValueUrl(specialService); CacheManager.Store(key, aspect, slidingExpiration: TimeSpan.FromMinutes(Config.AspectCacheSlidingExpirationTimeInMinutes)); } if (aspect.EnableLog) { // var actionLogManager = actionContext.Request.GetDependencyScope() //.GetService(typeof(Log.Base.IActionLogManager)) as Log.Base.IActionLogManager; _actionLogManager?.LogSpecialServices(aspect.Name, context.Request); } } } catch (Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); } await Next.Invoke(context); }
public Task OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken) { try { //var actionLogManager = actionContext.Request.GetDependencyScope() // .GetService(typeof(Log.Base.IActionLogManager)) as Log.Base.IActionLogManager; var serviceUrl = actionContext.Request.RequestUri.AbsolutePath; IAspect aspect; var result = AuthorizeManager.AuthorizeMasterDataKeyValueUrl(serviceUrl, ActionKey.RequestService, out aspect); if (aspect.EnableLog) { _actionLogManager?.LogOdataService(aspect.Name, actionContext.Request); } if (result) { return(Task.FromResult(0)); } actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized }; } catch (System.Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized }; } return(Task.FromResult(0)); }
public override async Task Invoke(IOwinContext context) { try { if (Settings.Culture != null) { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Settings.Language); Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Settings.Language + "-" + Settings.Culture); } } catch (Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); } await Next.Invoke(context); }
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()); } }
public Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken) { try { var requestedService = actionContext.Request.RequestUri.AbsolutePath; var routeTemplate = actionContext.RequestContext.RouteData.Route.RouteTemplate; if (actionContext.RequestContext.RouteData.Values.Count > 0) { var requestedServiceNormalUrl = requestedService[0] == '/' ? requestedService.Substring(1) : requestedService; var lastCharIndex = requestedServiceNormalUrl.Length - 1; requestedServiceNormalUrl = requestedServiceNormalUrl[lastCharIndex] == '/' ? requestedServiceNormalUrl.Substring(0, lastCharIndex - 1) : requestedServiceNormalUrl; var routeTemplateNormalUrl = routeTemplate[0] == '/' ? routeTemplate.Substring(1) : routeTemplate; lastCharIndex = routeTemplateNormalUrl.Length - 1; routeTemplateNormalUrl = routeTemplateNormalUrl[lastCharIndex] == '/' ? routeTemplateNormalUrl.Substring(0, lastCharIndex - 1) : routeTemplateNormalUrl; var requestedServiceToken = requestedServiceNormalUrl.ToLower().Split('/'); var routeTemplateToken = routeTemplateNormalUrl.ToLower().Split('/'); var tokenIndex = 0; requestedService = ""; foreach (var token in routeTemplateToken) { if (tokenIndex < requestedServiceToken.Length) { if (token == requestedServiceToken[tokenIndex]) { requestedService += "/" + token; } else { requestedService += "/@" + actionContext.RequestContext.RouteData.Values .Where(rv => token.Contains(rv.Key.ToLower())) .OrderByDescending(rv => rv.Key.Length) .FirstOrDefault().Key; } } tokenIndex++; } } IAspect aspect; var key = CacheManager.GetAspectKey(CacheKey.Aspect.ToString(), ActionKey.RequestService.ToString(), requestedService); if (CacheManager.Get <IAspect>(key).IsCached) { aspect = CacheManager.Get <IAspect>(key).Value; } else { aspect = _dataBaseContextManager.GetAspectForPublicMasterDataKeyValueUrl(requestedService); CacheManager.Store(key, aspect, slidingExpiration: TimeSpan.FromMinutes(Config.AspectCacheSlidingExpirationTimeInMinutes)); } if (aspect.EnableLog) { // var actionLogManager = actionContext.Request.GetDependencyScope() //.GetService(typeof(Log.Base.IActionLogManager)) as Log.Base.IActionLogManager; _actionLogManager?.LogHttpService(aspect.Name, actionContext.Request, requestedService); } } catch (Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); } return(Task.FromResult(0)); }
public Task OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken) { try { var requestedService = actionContext.Request.RequestUri.AbsolutePath; var routeTemplate = actionContext.RequestContext.RouteData.Route.RouteTemplate; if (actionContext.RequestContext.RouteData.Values.Count > 0) { var requestedServiceNormalUrl = requestedService[0] == '/' ? requestedService.Substring(1) : requestedService; var lastCharIndex = requestedServiceNormalUrl.Length - 1; requestedServiceNormalUrl = requestedServiceNormalUrl[lastCharIndex] == '/' ? requestedServiceNormalUrl.Substring(0, lastCharIndex - 1) : requestedServiceNormalUrl; var routeTemplateNormalUrl = routeTemplate[0] == '/' ? routeTemplate.Substring(1) : routeTemplate; lastCharIndex = routeTemplateNormalUrl.Length - 1; routeTemplateNormalUrl = routeTemplateNormalUrl[lastCharIndex] == '/' ? routeTemplateNormalUrl.Substring(0, lastCharIndex - 1) : routeTemplateNormalUrl; var requestedServiceToken = requestedServiceNormalUrl.ToLower().Split('/'); var routeTemplateToken = routeTemplateNormalUrl.ToLower().Split('/'); var tokenIndex = 0; requestedService = ""; foreach (var token in routeTemplateToken) { if (token == requestedServiceToken[tokenIndex]) { requestedService += "/" + token; } else { requestedService += "/@" + actionContext.RequestContext.RouteData.Values .Where(rv => token.Contains(rv.Key.ToLower())) .OrderByDescending(rv => rv.Key.Length) .FirstOrDefault().Key; } tokenIndex++; } } //var actionLogManager = actionContext.Request.GetDependencyScope() // .GetService(typeof(Log.Base.IActionLogManager)) as Log.Base.IActionLogManager; IAspect aspect; var result = AuthorizeManager.AuthorizeMasterDataKeyValueUrl(requestedService, ActionKey.RequestService, out aspect); if (aspect.EnableLog) { _actionLogManager?.LogHttpService(aspect.Name, actionContext.Request, requestedService); } if (result) { return(Task.FromResult(0)); } actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized }; } catch (System.Exception ex) { _errorLogManager.LogException(new ExceptionLog() { Detail = ex.ToString(), Message = ex.Message, Source = ex.GetType().FullName }); actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized }; } return(Task.FromResult(0)); }