コード例 #1
0
        /// <summary>
        /// ExecuteResult for errors list
        /// </summary>
        /// <param name="context">controller context</param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                return;
            }

            // try and get the resource from the {resource} part of the route
            var routeDataValues = context.RequestContext.RouteData.Values;
            var resource        = routeDataValues["resource"];

            if (resource == null)
            {
                // alternatively, try the {action}
                var action = routeDataValues["action"];
                // but only if it is elmah/Detail/{resource}
                if (action != null && DetailAction.Equals(action.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    resource = action;
                }
            }

            var httpContext = context.HttpContext;

            if (httpContext == null)
            {
                return;
            }

            var request     = httpContext.Request;
            var currentPath = request.Path;
            var queryString = request.QueryString;

            if (resource != null)
            {
                // make sure that ELMAH knows what the resource is
                var pathInfo = "." + resource;
                // also remove the resource from the path - else it will start chaining
                // e.g. /elmah/detail/detail/stylesheet
                var newPath = currentPath.Remove(currentPath.Length - pathInfo.Length);
                httpContext.RewritePath(newPath, pathInfo, queryString.ToString());
            }
            else
            {
                // we can't have paths such as elmah/ as the ELMAH handler will generate URIs such as elmah//stylesheet
                if (currentPath != null && currentPath.EndsWith("/"))
                {
                    var newPath = currentPath.Remove(currentPath.Length - 1);
                    httpContext.RewritePath(newPath, null, queryString.ToString());
                }
            }

            if (httpContext.ApplicationInstance != null)
            {
                var unwrappedHttpContext = httpContext.ApplicationInstance.Context;
                var handler = new ErrorLogPageFactory().GetHandler(unwrappedHttpContext, null, null, null);
                handler?.ProcessRequest(unwrappedHttpContext);
            }
        }
コード例 #2
0
ファイル: ElmahResult.cs プロジェクト: jamesmaxwell/elmah-mvc
        public override void ExecuteResult(ControllerContext context)
        {
            // try and get the resource from the {resource} part of the route
            var routeDataValues = context.RequestContext.RouteData.Values;
            var resource = routeDataValues["resource"];
            if (resource == null)
            {
                // alternatively, try the {action}
                var action = routeDataValues["action"].ToString();
                // but only if it is elmah/Detail/{resource}
                if ("Detail".Equals(action, StringComparison.OrdinalIgnoreCase))
                    resource = action;
            }

            var httpContext = context.HttpContext;
            var request = httpContext.Request;
            var currentPath = request.Path;
            var queryString = request.QueryString;
            if (resource != null)
            {
                // make sure that ELMAH knows what the resource is
                var pathInfo = "." + resource;
                // also remove the resource from the path - else it will start chaining
                // e.g. /elmah/detail/detail/stylesheet
                var newPath = currentPath.Remove(currentPath.Length - pathInfo.Length);
                httpContext.RewritePath(newPath, pathInfo, queryString.ToString());
            }
            else
            {
                // we can't have paths such as elmah/ as the ELMAH handler will generate URIs such as elmah//stylesheet
                if (currentPath.EndsWith("/"))
                {
                    var newPath = currentPath.Remove(currentPath.Length - 1);
                    httpContext.RewritePath(newPath, null, queryString.ToString());
                }
            }

            var unwrappedHttpContext = httpContext.ApplicationInstance.Context;
            var handler = new ErrorLogPageFactory().GetHandler(unwrappedHttpContext, null, null, null);
            if(handler != null)
            {
                handler.ProcessRequest(unwrappedHttpContext);
            }
        }
コード例 #3
0
        /// <summary>
        /// Executes the result.
        /// </summary>
        /// <param name="context">The controller context.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            object resource    = null;
            var    values      = context.RequestContext.RouteData.Values;
            var    httpContext = context.HttpContext;
            var    request     = httpContext.Request;
            var    path        = request.Path;
            var    queryString = request.QueryString;

            if (values.ContainsKey("resource"))
            {
                resource = values["resource"];

                // Ignore resource if it's the same as the action
                if (resource != null && resource.ToString().Equals(values["action"].ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    resource = null;
                }
            }

            if (resource != null)
            {
                // Rewrite path with resource included in a format useable by Elmah ErrorLogPageFactory
                string text = string.Format(".{0}", resource);

                httpContext.RewritePath(path.Remove(path.Length - text.Length), text, queryString.ToString());
            }
            else
            {
                if (path.EndsWith("/"))
                {
                    // Rewrite path with trailing slash removed
                    httpContext.RewritePath(path.TrimEnd('/'), null, queryString.ToString());
                }
            }

            IHttpHandler handler = new ErrorLogPageFactory().GetHandler(httpContext.ApplicationInstance.Context, null, null, null);

            handler.ProcessRequest(httpContext.ApplicationInstance.Context);
        }
コード例 #4
0
 protected virtual void ProcessRequest(HttpContextBase httpContext)
 {
     var unwrappedHttpContext = httpContext.ApplicationInstance.Context;
     var handler = new ErrorLogPageFactory().GetHandler(unwrappedHttpContext, null, null, null);
     handler.ProcessRequest(unwrappedHttpContext);
 }