static T TestAuthorization <T>(bool?allow, bool isLocalRequest, Func <HttpContextBase, IHttpHandler, T> resultor)
        {
            var mocks = new
            {
                Context = new Mock <HttpContextBase> {
                    DefaultValue = DefaultValue.Mock
                },
                Response = new Mock <HttpResponseBase> {
                    DefaultValue = DefaultValue.Mock
                },
            };

            using (var app = allow == null
                           ? new HttpApplication()
                           : new Application
            {
                AuthorizationHandler = _ => allow.Value
            })
            {
                mocks.Context.Setup(c => c.ApplicationInstance).Returns(app);
                mocks.Context.Setup(c => c.Request.PathInfo).Returns("/");
                mocks.Context.Setup(c => c.Request.IsLocal).Returns(isLocalRequest);
                mocks.Response.SetupAllProperties();
                mocks.Context.Setup(c => c.Response).Returns(mocks.Response.Object);
                mocks.Context.Setup(c => c.Items).Returns(new Hashtable());

                var context = mocks.Context.Object;
                var factory = new ErrorLogPageFactory();
                var handler = factory.GetHandler(context, null, null, null);
                return(resultor(context, handler));
            }
        }
Exemplo n.º 2
0
        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);
                if (handler != null)
                {
                    handler.ProcessRequest(unwrappedHttpContext);
                }
            }
        }
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var factory = new ErrorLogPageFactory();

            if (!string.IsNullOrEmpty(this.resouceType))
            {
                var pathInfo = "/" + this.resouceType;
                context.HttpContext.RewritePath(this.FilePath(context), pathInfo, context.HttpContext.Request.QueryString.ToString());
            }

            var currentContext = GetCurrentContextAsHttpContext(context);

            var httpHandler      = factory.GetHandler(currentContext, null, null, null);
            var httpAsyncHandler = httpHandler as IHttpAsyncHandler;

            if (httpAsyncHandler != null)
            {
                httpAsyncHandler.BeginProcessRequest(currentContext, r => { }, null);
                return;
            }

            httpHandler.ProcessRequest(currentContext);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public override void ExecuteResult(ControllerContext context)
        {
            var factory = new ErrorLogPageFactory();

            if (!string.IsNullOrEmpty(_resouceType))
            {
                var pathInfo = "/" + _resouceType;
                context.HttpContext.RewritePath(FilePath(context), pathInfo, context.HttpContext.Request.QueryString.ToString());
            }

            var currentContext = GetCurrentContext(context);

            var httpHandler = factory.GetHandler(currentContext, null, null, null);

            if (httpHandler is IHttpAsyncHandler httpAsyncHandler)
            {
                httpAsyncHandler.BeginProcessRequest(currentContext, r => { }, null);
                return;
            }

            httpHandler.ProcessRequest(currentContext);
        }
        public override void ExecuteResult(ControllerContext context)
        {
            var factory = new ErrorLogPageFactory();

            if (!string.IsNullOrEmpty(_resouceType))
            {
                var pathInfo = "/" + _resouceType;
                context.HttpContext.RewritePath(FilePath(context), pathInfo, context.HttpContext.Request.QueryString.ToString());
            }

            var currentContext = GetCurrentContext(context);

            var httpHandler = factory.GetHandler(currentContext, null, null, null);
            var httpAsyncHandler = httpHandler as IHttpAsyncHandler;

            if (httpAsyncHandler != null)
            {
                httpAsyncHandler.BeginProcessRequest(currentContext, r => { }, null);
                return;
            }

            httpHandler.ProcessRequest(currentContext);
        }
 protected virtual void ProcessRequest(HttpContextBase httpContext)
 {
     var unwrappedHttpContext = httpContext.ApplicationInstance.Context;
     var handler = new ErrorLogPageFactory().GetHandler(unwrappedHttpContext, null, null, null);
     handler.ProcessRequest(unwrappedHttpContext);
 }