Пример #1
0
 public void OnResultExecuted(ResultExecutedContext context)
 {
     var headerName = "OnResultExecuted";
     context.HttpContext.Response.Headers.Add(
         headerName, new string[] { "ResultExecutedSuccessfully" });
     _logger.LogInformation($"Header added: {headerName}");
 }
Пример #2
0
 public void OnResultExecuted(ResultExecutedContext context)
 {
     var time = _timer.ElapsedMilliseconds;
     context.HttpContext.Response.Headers.Add(
         "ResultElapsedTime",
         new string[] { time.ToString(CultureInfo.InvariantCulture) + " ms" });
 }
Пример #3
0
        public override void OnResultExecuted(ResultExecutedContext context)
        {
            context.HttpContext.Response.Headers.Add(
                "OnResultExecuted", new string[] { "ResultExecutedSuccessfully" });

            base.OnResultExecuted(context);
        }
Пример #4
0
 /// <inheritdoc />
 public void OnResultExecuted(ResultExecutedContext context)
 {
     if (context.Result is IKeepTempDataResult)
     {
         _tempData.Keep();
     }
 }
Пример #5
0
 public void OnResultExecuted(ResultExecutedContext context)
 {
     var controllerActionDescriptor = (ControllerActionDescriptor)context.ActionDescriptor;
     if (controllerActionDescriptor.MethodInfo ==
         typeof(ProductsController).GetMethod(nameof(ProductsController.GetPrice)))
     {
         context.HttpContext.Response.Headers.Append("filters",
             "Global Result Filter - OnResultExecuted");
     }
 }
        public void PropertiesAreSetByConstructor()
        {
            // Arrange
            ControllerContext controllerContext = new Mock<ControllerContext>().Object;
            ActionResult result = new ViewResult();
            bool canceled = true;
            Exception exception = new Exception();

            // Act
            ResultExecutedContext resultExecutedContext = new ResultExecutedContext(controllerContext, result, canceled, exception);

            // Assert
            Assert.Equal(result, resultExecutedContext.Result);
            Assert.Equal(canceled, resultExecutedContext.Canceled);
            Assert.Equal(exception, resultExecutedContext.Exception);
        }
Пример #7
0
        public void SaveTempDataFilter_OnResultExecuted_DoesNotKeepTempData_ForNonIKeepTempDataResult()
        {
            // Arrange
            var tempData = new Mock<ITempDataDictionary>(MockBehavior.Strict);

            var tempDataFactory = new Mock<ITempDataDictionaryFactory>(MockBehavior.Strict);
            tempDataFactory
                .Setup(f => f.GetTempData(It.IsAny<HttpContext>()))
                .Returns(tempData.Object);

            var filter = new SaveTempDataFilter(tempDataFactory.Object);

            var context = new ResultExecutedContext(
                new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                new IFilterMetadata[] { },
                new Mock<IActionResult>().Object,
                new object());

            // Act
            filter.OnResultExecuted(context);

            // Assert - The mock will throw if we do the wrong thing.
        }
        public static void BeforeOnResultExecuted(
            this DiagnosticSource diagnosticSource,
            ResultExecutedContext resultExecutedContext,
            IResultFilter filter)
        {
            Debug.Assert(diagnosticSource != null);
            Debug.Assert(resultExecutedContext != null);
            Debug.Assert(filter != null);

            if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted"))
            {
                diagnosticSource.Write(
                    "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted",
                    new
                    {
                        actionDescriptor = resultExecutedContext.ActionDescriptor,
                        resultExecutedContext = resultExecutedContext,
                        filter = filter
                    });
            }
        }
Пример #9
0
        public void SaveTempDataFilter_OnResultExecuted_KeepsTempData_ForIKeepTempDataResult()
        {
            // Arrange
            var tempData = new Mock<ITempDataDictionary>(MockBehavior.Strict);
            tempData
                .Setup(m => m.Keep())
                .Verifiable();

            var tempDataFactory = new Mock<ITempDataDictionaryFactory>(MockBehavior.Strict);
            tempDataFactory
                .Setup(f => f.GetTempData(It.IsAny<HttpContext>()))
                .Returns(tempData.Object);

            var filter = new SaveTempDataFilter(tempDataFactory.Object);

            var context = new ResultExecutedContext(
                new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
                new IFilterMetadata[] { },
                new Mock<IKeepTempDataResult>().Object,
                new object());

            // Act
            filter.OnResultExecuted(context);

            // Assert
            tempData.Verify();
        }
        private async Task<ResultExecutedContext> InvokeActionResultFilterRecursiveAsync(IList<IResultFilter> filters, int filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
        {
            // Performance-sensitive

            // For compatbility, the following behavior must be maintained
            //   The OnResultExecuting events must fire in forward order
            //   The InvokeActionResultAsync must then fire
            //   The OnResultExecuted events must fire in reverse order
            //   Earlier filters can process the results and exceptions from the handling of later filters
            // This is achieved by calling recursively and moving through the filter list forwards

            // If there are no more filters to recurse over, create the main result
            if (filterIndex > filters.Count - 1)
            {
                await InvokeActionResultAsync(controllerContext, actionResult).ConfigureAwait(false);
                return new ResultExecutedContext(controllerContext, actionResult, canceled: false, exception: null);
            }

            // Otherwise process the filters recursively
            IResultFilter filter = filters[filterIndex];
            filter.OnResultExecuting(preContext);
            if (preContext.Cancel)
            {
                return new ResultExecutedContext(preContext, preContext.Result, canceled: true, exception: null);
            }

            bool wasError = false;
            ResultExecutedContext postContext = null;
            try
            {
                // Use the filters in forward direction
                int nextFilterIndex = filterIndex + 1;
                postContext = await InvokeActionResultFilterRecursiveAsync(filters, nextFilterIndex, preContext, controllerContext, actionResult).ConfigureAwait(false);
            }
            catch (ThreadAbortException)
            {
                // This type of exception occurs as a result of Response.Redirect(), but we special-case so that
                // the filters don't see this as an error.
                postContext = new ResultExecutedContext(preContext, preContext.Result, canceled: false, exception: null);
                filter.OnResultExecuted(postContext);
                throw;
            }
            catch (Exception ex)
            {
                wasError = true;
                postContext = new ResultExecutedContext(preContext, preContext.Result, canceled: false, exception: ex);
                filter.OnResultExecuted(postContext);
                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }
            if (!wasError)
            {
                filter.OnResultExecuted(postContext);
            }
            return postContext;
        }
Пример #11
0
 public void OnResultExecuted(ResultExecutedContext context)
 {
 }
Пример #12
0
 protected override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     DisposeService(filterContext);
 }
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     try
     {
         Thread.ResetAbort();
     }
     catch (ThreadStateException)
     {
         // thread wasn't being aborted
     }
 }
Пример #14
0
 public virtual void OnResultExecuted(ResultExecutedContext context)
 {
     sw.Stop();
     Log.Costs = sw.ElapsedMilliseconds;
 }
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     Helpers.LogWebUsage(_productName, _layerName, _name);
 }
 public void OnResultExecuted(ResultExecutedContext context)
 {
     Console.WriteLine("Executing IResultFilter.OnResultExecuted");
 }
Пример #17
0
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     filterContext.HttpContext.Response.Write("4.OnResultExecuted");
 }
Пример #18
0
 /// <summary>
 /// 结果执行结束
 /// </summary>
 /// <param name="filterContext"></param>
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     Log("OnResultExecuted", filterContext.RouteData);
 }
Пример #19
0
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            // This filter is not reentrant (multiple executions within the same request are
            // not supported) so child actions are ignored completely.
            if (filterContext.IsChildAction)
            {
                return;
            }

            var captureHandlerIsAttached = false;

            try {
                if (!_isCachingRequest)
                {
                    return;
                }

                Logger.Debug("Item '{0}' was rendered.", _cacheKey);


                if (!ResponseIsCacheable(filterContext))
                {
                    filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    filterContext.HttpContext.Response.Cache.SetNoStore();
                    filterContext.HttpContext.Response.Cache.SetMaxAge(new TimeSpan(0));
                    return;
                }

                // Determine duration and grace time.
                var cacheDuration  = _cacheRouteConfig != null && _cacheRouteConfig.Duration.HasValue ? _cacheRouteConfig.Duration.Value : CacheSettings.DefaultCacheDuration;
                var cacheGraceTime = _cacheRouteConfig != null && _cacheRouteConfig.GraceTime.HasValue ? _cacheRouteConfig.GraceTime.Value : CacheSettings.DefaultCacheGraceTime;

                // Include each content item ID as tags for the cache entry.
                var contentItemIds = _displayedContentItemHandler.GetDisplayed().Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();

                // Capture the response output using a custom filter stream.
                var response      = filterContext.HttpContext.Response;
                var captureStream = new CaptureStream(response.Filter);
                response.Filter = captureStream;

                // Add ETag header for the newly created item
                var etag = Guid.NewGuid().ToString("n");
                if (HttpRuntime.UsingIntegratedPipeline)
                {
                    if (response.Headers.Get("ETag") == null)
                    {
                        response.Headers["ETag"] = etag;
                    }
                }

                captureStream.Captured += (output) => {
                    try {
                        // Since this is a callback any call to injected dependencies can result in an Autofac exception: "Instances
                        // cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed."
                        // To prevent access to the original lifetime scope a new work context scope should be created here and dependencies
                        // should be resolved from it.

                        // Recheck the response status code incase it was modified before the callback.
                        if (response.StatusCode != 200)
                        {
                            Logger.Debug("Response for item '{0}' will not be cached because status code was set to {1} during rendering.", _cacheKey, response.StatusCode);
                            return;
                        }

                        using (var scope = _workContextAccessor.CreateWorkContextScope()) {
                            var cacheItem = new CacheItem()
                            {
                                CachedOnUtc       = _now,
                                Duration          = cacheDuration,
                                GraceTime         = cacheGraceTime,
                                Output            = output,
                                ContentType       = response.ContentType,
                                QueryString       = filterContext.HttpContext.Request.Url.Query,
                                CacheKey          = _cacheKey,
                                InvariantCacheKey = _invariantCacheKey,
                                Url        = filterContext.HttpContext.Request.Url.AbsolutePath,
                                Tenant     = scope.Resolve <ShellSettings>().Name,
                                StatusCode = response.StatusCode,
                                Tags       = new[] { _invariantCacheKey }.Union(contentItemIds).ToArray(),
                                ETag       = etag
                            };

                            // Write the rendered item to the cache.
                            var cacheStorageProvider = scope.Resolve <IOutputCacheStorageProvider>();
                            cacheStorageProvider.Set(_cacheKey, cacheItem);

                            Logger.Debug("Item '{0}' was written to cache.", _cacheKey);

                            // Also add the item tags to the tag cache.
                            var tagCache = scope.Resolve <ITagCache>();
                            foreach (var tag in cacheItem.Tags)
                            {
                                tagCache.Tag(tag, _cacheKey);
                            }
                        }
                    }
                    finally {
                        // Always release the cache key lock when the request ends.
                        ReleaseCacheKeyLock();
                    }
                };

                captureHandlerIsAttached = true;
            }
            finally {
                // If the response filter stream capture handler was attached then we'll trust
                // it to release the cache key lock at some point in the future when the stream
                // is flushed; otherwise we'll make sure we'll release it here.
                if (!captureHandlerIsAttached)
                {
                    ReleaseCacheKeyLock();
                }
            }
        }
Пример #20
0
        private Task ResultNext <TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
            where TFilter : class, IResultFilter
            where TFilterAsync : class, IAsyncResultFilter
        {
            var resultFilterKind = typeof(TFilter) == typeof(IAlwaysRunResultFilter) ?
                                   FilterTypeConstants.AlwaysRunResultFilter :
                                   FilterTypeConstants.ResultFilter;

            switch (next)
            {
            case State.ResultBegin:
            {
                _cursor.Reset();
                goto case State.ResultNext;
            }

            case State.ResultNext:
            {
                var current = _cursor.GetNextFilter <TFilter, TFilterAsync>();
                if (current.FilterAsync != null)
                {
                    if (_resultExecutingContext == null)
                    {
                        _resultExecutingContext = new ResultExecutingContext(_actionContext, _filters, _result, _instance);
                    }

                    state = current.FilterAsync;
                    goto case State.ResultAsyncBegin;
                }
                else if (current.Filter != null)
                {
                    if (_resultExecutingContext == null)
                    {
                        _resultExecutingContext = new ResultExecutingContext(_actionContext, _filters, _result, _instance);
                    }

                    state = current.Filter;
                    goto case State.ResultSyncBegin;
                }
                else
                {
                    goto case State.ResultInside;
                }
            }

            case State.ResultAsyncBegin:
            {
                Debug.Assert(state != null);
                Debug.Assert(_resultExecutingContext != null);

                var filter = (TFilterAsync)state;
                var resultExecutingContext = _resultExecutingContext;

                _diagnosticSource.BeforeOnResultExecution(resultExecutingContext, filter);
                _logger.BeforeExecutingMethodOnFilter(
                    resultFilterKind,
                    nameof(IAsyncResultFilter.OnResultExecutionAsync),
                    filter);

                var task = filter.OnResultExecutionAsync(resultExecutingContext, InvokeNextResultFilterAwaitedAsync <TFilter, TFilterAsync>);
                if (task.Status != TaskStatus.RanToCompletion)
                {
                    next = State.ResultAsyncEnd;
                    return(task);
                }

                goto case State.ResultAsyncEnd;
            }

            case State.ResultAsyncEnd:
            {
                Debug.Assert(state != null);
                Debug.Assert(_resultExecutingContext != null);

                var filter = (TFilterAsync)state;
                var resultExecutingContext = _resultExecutingContext;
                var resultExecutedContext  = _resultExecutedContext;

                if (resultExecutedContext == null || resultExecutingContext.Cancel)
                {
                    // Short-circuited by not calling next || Short-circuited by setting Cancel == true
                    _logger.ResultFilterShortCircuited(filter);

                    _resultExecutedContext = new ResultExecutedContext(
                        _actionContext,
                        _filters,
                        resultExecutingContext.Result,
                        _instance)
                    {
                        Canceled = true,
                    };
                }

                _diagnosticSource.AfterOnResultExecution(_resultExecutedContext, filter);
                _logger.AfterExecutingMethodOnFilter(
                    resultFilterKind,
                    nameof(IAsyncResultFilter.OnResultExecutionAsync),
                    filter);

                goto case State.ResultEnd;
            }

            case State.ResultSyncBegin:
            {
                Debug.Assert(state != null);
                Debug.Assert(_resultExecutingContext != null);

                var filter = (TFilter)state;
                var resultExecutingContext = _resultExecutingContext;

                _diagnosticSource.BeforeOnResultExecuting(resultExecutingContext, filter);
                _logger.BeforeExecutingMethodOnFilter(
                    resultFilterKind,
                    nameof(IResultFilter.OnResultExecuting),
                    filter);

                filter.OnResultExecuting(resultExecutingContext);

                _diagnosticSource.AfterOnResultExecuting(resultExecutingContext, filter);
                _logger.AfterExecutingMethodOnFilter(
                    resultFilterKind,
                    nameof(IResultFilter.OnResultExecuting),
                    filter);

                if (_resultExecutingContext.Cancel)
                {
                    // Short-circuited by setting Cancel == true
                    _logger.ResultFilterShortCircuited(filter);

                    _resultExecutedContext = new ResultExecutedContext(
                        resultExecutingContext,
                        _filters,
                        resultExecutingContext.Result,
                        _instance)
                    {
                        Canceled = true,
                    };

                    goto case State.ResultEnd;
                }

                var task = InvokeNextResultFilterAsync <TFilter, TFilterAsync>();
                if (task.Status != TaskStatus.RanToCompletion)
                {
                    next = State.ResultSyncEnd;
                    return(task);
                }

                goto case State.ResultSyncEnd;
            }

            case State.ResultSyncEnd:
            {
                Debug.Assert(state != null);
                Debug.Assert(_resultExecutingContext != null);
                Debug.Assert(_resultExecutedContext != null);

                var filter = (TFilter)state;
                var resultExecutedContext = _resultExecutedContext;

                _diagnosticSource.BeforeOnResultExecuted(resultExecutedContext, filter);
                _logger.BeforeExecutingMethodOnFilter(
                    resultFilterKind,
                    nameof(IResultFilter.OnResultExecuted),
                    filter);

                filter.OnResultExecuted(resultExecutedContext);

                _diagnosticSource.AfterOnResultExecuted(resultExecutedContext, filter);
                _logger.AfterExecutingMethodOnFilter(
                    resultFilterKind,
                    nameof(IResultFilter.OnResultExecuted),
                    filter);

                goto case State.ResultEnd;
            }

            case State.ResultInside:
            {
                // If we executed result filters then we need to grab the result from there.
                if (_resultExecutingContext != null)
                {
                    _result = _resultExecutingContext.Result;
                }

                if (_result == null)
                {
                    // The empty result is always flowed back as the 'executed' result if we don't have one.
                    _result = new EmptyResult();
                }

                var task = InvokeResultAsync(_result);
                if (task.Status != TaskStatus.RanToCompletion)
                {
                    next = State.ResultEnd;
                    return(task);
                }

                goto case State.ResultEnd;
            }

            case State.ResultEnd:
            {
                var result = _result;
                isCompleted = true;

                if (scope == Scope.Result)
                {
                    if (_resultExecutedContext == null)
                    {
                        _resultExecutedContext = new ResultExecutedContext(_actionContext, _filters, result, _instance);
                    }

                    return(Task.CompletedTask);
                }

                Rethrow(_resultExecutedContext);
                return(Task.CompletedTask);
            }

            default:
                throw new InvalidOperationException();     // Unreachable.
            }
        }
Пример #21
0
 protected override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     ServiceApplication.DisposeService(filterContext);
 }
Пример #22
0
 public void OnResultExecuted(ResultExecutedContext context)
 {
     context.HttpContext.Response.StatusCode = _statusCode;
 }
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     base.OnResultExecuted(filterContext);
     dumpData(filterContext, "OnResultExecuted");
 }
Пример #24
0
 public virtual void OnResultExecuted(ResultExecutedContext context)
 {
     //no action
 }
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     filterContext.HttpContext.Response.Cookies.Remove(
         FormsAuthentication.FormsCookieName);
 }
Пример #26
0
 public override void OnResultExecuted(ResultExecutedContext context)
 {
     Console.WriteLine("@@OnResultExecuted:" + this.GetType().Name);
     base.OnResultExecuted(context);
 }
Пример #27
0
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     timer.Stop();
     filterContext.HttpContext.Response.Write(string.Format("<div>Total elapsed time: {0:F6}</div>", timer.Elapsed.TotalSeconds));
 }
Пример #28
0
 /// <summary>
 /// ActionResult执行之后先执行此方法
 /// </summary>
 /// <param name="filterContext">过滤器上下文</param>
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     base.OnResultExecuted(filterContext);
     HttpContext.Current.Response.Write("<br />OnResultExecuted :" + Name);
 }
Пример #29
0
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            var response = filterContext.HttpContext.Response;

            response.ContentType = "text/javascript";
        }
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     base.OnResultExecuted(filterContext);
 }
Пример #31
0
 public override void OnResultExecuted(ResultExecutedContext context)
 {
 }
Пример #32
0
        private byte[] generateCacheData(ResultExecutedContext context)
        {
            Dictionary <string, object> cacheData = new Dictionary <string, object>();

            // Cache Request params:
            cacheData.Add("Request.Method", context.HttpContext.Request.Method);
            cacheData.Add("Request.Path", context.HttpContext.Request.Path.HasValue ? context.HttpContext.Request.Path.Value : string.Empty);
            cacheData.Add("Request.QueryString", context.HttpContext.Request.QueryString.ToUriComponent());
            cacheData.Add("Request.DataHash", getRequestsDataHash(context.HttpContext.Request));

            //Cache Response params:
            cacheData.Add("Response.StatusCode", context.HttpContext.Response.StatusCode);
            cacheData.Add("Response.ContentType", context.HttpContext.Response.ContentType);

            Dictionary <string, List <string> > Headers = context.HttpContext.Response.Headers.ToDictionary(h => h.Key, h => h.Value.ToList());

            cacheData.Add("Response.Headers", Headers);


            // 2019-07-05: Response.Body cannot be accessed because its not yet created.
            // We are saving the Context.Result, because based on this the Response.Body is created.
            Dictionary <string, object> resultObjects = new Dictionary <string, object>();
            var contextResult = context.Result;

            resultObjects.Add("ResultType", contextResult.GetType().AssemblyQualifiedName);

            if (contextResult is CreatedAtRouteResult route)
            {
                //CreatedAtRouteResult.CreatedAtRouteResult(string routeName, object routeValues, object value)
                resultObjects.Add("ResultValue", route.Value);
                resultObjects.Add("ResultRouteName", route.RouteName);

                Dictionary <string, string> RouteValues = route.RouteValues.ToDictionary(r => r.Key, r => r.Value.ToString());
                resultObjects.Add("ResultRouteValues", RouteValues);
            }
            else if (contextResult is ObjectResult objectResult)
            {
                if (objectResult.Value.isAnonymousType())
                {
                    resultObjects.Add("ResultValue", Utils.AnonymousObjectToDictionary(objectResult.Value, Convert.ToString));
                }
                else
                {
                    resultObjects.Add("ResultValue", objectResult.Value);
                }
            }
            else if (contextResult is StatusCodeResult || contextResult is ActionResult)
            {
                // Known types that do not need additional data
            }
            else
            {
                throw new NotImplementedException($"ApplyPostIdempotency.generateCacheData is not implement for IActionResult type {contextResult.GetType().ToString()}");
            }

            cacheData.Add("Context.Result", resultObjects);


            // Serialize & Compress data:
            return(cacheData.Serialize());
        }
Пример #33
0
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
     Console.WriteLine("Result已经执行了!");
 }
Пример #34
0
        public override void OnResultExecuted(ResultExecutedContext context)
        {
            var ctrl        = context.Controller as IBaseController;
            var ctrlActDesc = context.ActionDescriptor as ControllerActionDescriptor;

            //如果是来自Error,则已经记录过日志,跳过
            if (ctrlActDesc.ControllerName == "_Framework" && ctrlActDesc.ActionName == "Error")
            {
                return;
            }
            if (ctrl.ConfigInfo.EnableLog == true)
            {
                if (ctrl.ConfigInfo.LogExceptionOnly == false || context.Exception != null)
                {
                    var log     = new ActionLog();
                    var ctrlDes = ctrlActDesc.ControllerTypeInfo.GetCustomAttributes(typeof(ActionDescriptionAttribute), false).Cast <ActionDescriptionAttribute>().FirstOrDefault();
                    var actDes  = ctrlActDesc.MethodInfo.GetCustomAttributes(typeof(ActionDescriptionAttribute), false).Cast <ActionDescriptionAttribute>().FirstOrDefault();
                    var postDes = ctrlActDesc.MethodInfo.GetCustomAttributes(typeof(HttpPostAttribute), false).Cast <HttpPostAttribute>().FirstOrDefault();

                    log.LogType    = context.Exception == null ? ActionLogTypesEnum.Normal : ActionLogTypesEnum.Exception;
                    log.ActionTime = DateTime.Now;
                    log.ITCode     = ctrl.LoginUserInfo?.ITCode ?? string.Empty;
                    // 给日志的多语言属性赋值
                    log.ModuleName = ctrlDes?.Description ?? ctrlActDesc.ControllerName;
                    log.ActionName = actDes?.Description ?? ctrlActDesc.ActionName + (postDes == null ? string.Empty : "[P]");
                    log.ActionUrl  = context.HttpContext.Request.Path;
                    log.IP         = context.HttpContext.GetRemoteIpAddress();
                    log.Remark     = context.Exception?.ToString() ?? string.Empty;
                    if (string.IsNullOrEmpty(log.Remark) == false && log.Remark.Length > 1000)
                    {
                        log.Remark = log.Remark.Substring(0, 1000);
                    }
                    var starttime = context.HttpContext.Items["actionstarttime"] as DateTime?;
                    if (starttime != null)
                    {
                        log.Duration = DateTime.Now.Subtract(starttime.Value).TotalSeconds;
                    }
                    try
                    {
                        using (var dc = ctrl.CreateDC(true))
                        {
                            dc.Set <ActionLog>().Add(log);
                            dc.SaveChanges();
                        }
                    }
                    catch { }
                }
            }
            if (context.Exception != null)
            {
                context.ExceptionHandled = true;
                if (ctrl.ConfigInfo.IsQuickDebug == true)
                {
                    context.HttpContext.Response.WriteAsync(context.Exception.ToString());
                }
                else
                {
                    context.HttpContext.Response.WriteAsync("页面发生错误");
                }
            }
            base.OnResultExecuted(context);
        }
 public void OnResultExecuted(ResultExecutedContext context)
 {
 }
Пример #36
0
 public virtual void OnResultExecuted(ResultExecutedContext filterContext)
 {
     // Intentionally left blank to allow for a better overriding experience
 }
 public static void AfterOnResultExecuted(
     this DiagnosticSource diagnosticSource,
     ActionDescriptor actionDescriptor,
     ResultExecutedContext resultExecutedContext,
     IResultFilter filter)
 {
     if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuted"))
     {
         diagnosticSource.Write(
             "Microsoft.AspNetCore.Mvc.AfterOnResultExecuted",
             new
             {
                 actionDescriptor = actionDescriptor,
                 resultExecutedContext = resultExecutedContext,
                 filter = filter
             });
     }
 }
Пример #38
0
 public void OnResultExecuted(ResultExecutedContext context)
 {
     context.HttpContext.Response.Headers.Append("filters", "Controller Override - OnResultExecuted");
 }
 public override void OnResultExecuted(ResultExecutedContext context)
 {
     _logger.LogInformation("OnResultExecuted");
     base.OnResultExecuted(context);
 }
Пример #40
0
 public override void OnResultExecuted(ResultExecutedContext context)
 {
     _logger.LogInformation("OnResultExecuted");
     base.OnResultExecuted(context);
 }
Пример #41
0
 public override void OnResultExecuted(ResultExecutedContext context)
 {
     DebugMessage("ClassFilter OnResultExecuted");
     base.OnResultExecuted(context);
 }
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
     throw new NotImplementedException();
 }
Пример #43
0
 protected override void OnResultExecuted(ResultExecutedContext executedContext)
 {
     //在这里可以处理最终输出到浏览器的html
     //string html = RenderViewToString(this, ((ViewResult)executedContext.Result).View);
     base.OnResultExecuted(executedContext);
 }
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
     ExecuteFilterWhenItIs <IResultFilter>(f => f.OnResultExecuted(filterContext));
 }
Пример #45
0
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
     throw new NotImplementedException();
 }
 public override void OnResultExecuted(ResultExecutedContext context)
 {
     _logger.LogWarning("ClassFilter OnResultExecuted");
     base.OnResultExecuted(context);
 }
Пример #47
0
 /// <inheritdocs/>
 public void OnResultExecuted(ResultExecutedContext context)
 {
     // Can't add to headers here because response has already begun.
 }
 public virtual void OnResultExecuted(ResultExecutedContext filterContext)
 {
 }
Пример #49
0
 public override void OnResultExecuted(ResultExecutedContext context)
 {
     WriteMessage(context, $"<div>After Result:{message}</div>");
 }
 public void OnResultExecuted(ResultExecutedContext context)
 {
     //no action
 }
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
 }
 public void OnResultExecuted(ResultExecutedContext filterContext)
 {
     if (OnResultExecutedImpl != null)
     {
         OnResultExecutedImpl(filterContext);
     }
 }
Пример #53
0
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     filterContext.HttpContext.Response.AppendHeader(Name, Value);
     base.OnResultExecuted(filterContext);
 }