Elmah.ErrorLogPageFactory.GetHandler C# (CSharp) Méthode

GetHandler() public méthode

Returns an object that implements the IHttpHandler interface and which is responsible for serving the request.
public GetHandler ( System.Web.HttpContextBase context, string requestType, string url, string pathTranslated ) : IHttpHandler
context System.Web.HttpContextBase
requestType string
url string
pathTranslated string
Résultat IHttpHandler
        public virtual IHttpHandler GetHandler(HttpContextBase context, string requestType, string url, string pathTranslated)
        {
            //
            // The request resource is determined by the looking up the
            // value of the PATH_INFO server variable.
            //

            var request = context.Request;
            var resource = request.PathInfo.Length == 0
                         ? string.Empty
                         : request.PathInfo.Substring(1).ToLowerInvariant();

            var handler = FindHandler(resource);

            if (handler == null)
                throw new HttpException(404, "Resource not found.");

            //
            // Check if authorized then grant or deny request.
            //

            var authorized = IsAuthorized(context);
            if (authorized == false
                || (authorized == null // Compatibility case...
                    && !request.IsLocal
                    && !SecurityConfiguration.Default.AllowRemoteAccess))
            {
                ManifestResourceHandler.Create("RemoteAccessError.htm", "text/html")(context);
                var response = context.Response;
                response.Status = "403 Forbidden";
                response.End();

                //
                // HttpResponse.End docs say that it throws
                // ThreadAbortException and so should never end up here but
                // that's not been the observation in the debugger. So as a
                // precautionary measure, bail out anyway.
                //

                return null;
            }

            return handler;
        }

Usage Example

Exemple #1
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 currentApplication = (HttpApplication) context.HttpContext.GetService(typeof (HttpApplication));

            if (currentApplication == null)
                return;

            var currentContext = currentApplication.Context;

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

            if (handler != null)
            {
                var asyncHttpHandler = handler;
                asyncHttpHandler.BeginProcessRequest(currentContext, (r) => { }, null);
            }
            else
            {
                if (httpHandler != null)
                    httpHandler.ProcessRequest(currentContext);
            }
        }
All Usage Examples Of Elmah.ErrorLogPageFactory::GetHandler