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));
        }
示例#2
0
        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));
        }