Esempio n. 1
0
        internal IHttpHandler CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
        {
            TraceMethod method = Tracing.On ? new TraceMethod(this, "CoreGetHandler", new object[0]) : null;

            ServerProtocolFactory[] serverProtocolFactories = this.GetServerProtocolFactories();
            ServerProtocol          protocol = null;
            bool abortProcessing             = false;

            for (int i = 0; i < serverProtocolFactories.Length; i++)
            {
                try
                {
                    protocol = serverProtocolFactories[i].Create(type, context, request, response, out abortProcessing);
                    if (((protocol != null) && (protocol.GetType() != typeof(UnsupportedRequestProtocol))) || abortProcessing)
                    {
                        break;
                    }
                }
                catch (Exception exception)
                {
                    if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                    {
                        throw;
                    }
                    throw Tracing.ExceptionThrow(method, new InvalidOperationException(Res.GetString("FailedToHandleRequest0"), exception));
                }
            }
            if (abortProcessing)
            {
                return(new NopHandler());
            }
            if (protocol == null)
            {
                if ((request.PathInfo != null) && (request.PathInfo.Length != 0))
                {
                    throw Tracing.ExceptionThrow(method, new InvalidOperationException(Res.GetString("WebUnrecognizedRequestFormatUrl", new object[] { request.PathInfo })));
                }
                throw Tracing.ExceptionThrow(method, new InvalidOperationException(Res.GetString("WebUnrecognizedRequestFormat")));
            }
            if (protocol is UnsupportedRequestProtocol)
            {
                throw Tracing.ExceptionThrow(method, new HttpException(((UnsupportedRequestProtocol)protocol).HttpCode, Res.GetString("WebUnrecognizedRequestFormat")));
            }
            bool isAsync       = protocol.MethodInfo.IsAsync;
            bool enableSession = protocol.MethodAttribute.EnableSession;

            if (isAsync)
            {
                if (enableSession)
                {
                    return(new AsyncSessionHandler(protocol));
                }
                return(new AsyncSessionlessHandler(protocol));
            }
            if (enableSession)
            {
                return(new SyncSessionHandler(protocol));
            }
            return(new SyncSessionlessHandler(protocol));
        }
Esempio n. 2
0
        internal IHttpHandler CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
        {
            TraceMethod caller = Tracing.On ? new TraceMethod(this, "CoreGetHandler") : null;

            ServerProtocolFactory[] protocolFactories = GetServerProtocolFactories();
            ServerProtocol          protocol          = null;
            bool abort = false;

            for (int i = 0; i < protocolFactories.Length; i++)
            {
                try {
                    protocol = protocolFactories[i].Create(type, context, request, response, out abort);
                    if ((protocol != null && protocol.GetType() != typeof(UnsupportedRequestProtocol)) || abort)
                    {
                        break;
                    }
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw Tracing.ExceptionThrow(caller, new InvalidOperationException(Res.GetString(Res.FailedToHandleRequest0), e));
                }
            }

            if (abort)
            {
                return(new NopHandler());
            }

            if (protocol == null)
            {
                if (request.PathInfo != null && request.PathInfo.Length != 0)
                {
                    throw Tracing.ExceptionThrow(caller, new InvalidOperationException(Res.GetString(Res.WebUnrecognizedRequestFormatUrl,
                                                                                                     new object[] { request.PathInfo })));
                }
                else
                {
                    throw Tracing.ExceptionThrow(caller, new InvalidOperationException(Res.GetString(Res.WebUnrecognizedRequestFormat)));
                }
            }
            else if (protocol is UnsupportedRequestProtocol)
            {
                throw Tracing.ExceptionThrow(caller, new HttpException(((UnsupportedRequestProtocol)protocol).HttpCode, Res.GetString(Res.WebUnrecognizedRequestFormat)));
            }

            bool isAsync         = protocol.MethodInfo.IsAsync;
            bool requiresSession = protocol.MethodAttribute.EnableSession;

            if (isAsync)
            {
                if (requiresSession)
                {
                    return(new AsyncSessionHandler(protocol));
                }
                else
                {
                    return(new AsyncSessionlessHandler(protocol));
                }
            }
            else
            {
                if (requiresSession)
                {
                    return(new SyncSessionHandler(protocol));
                }
                else
                {
                    return(new SyncSessionlessHandler(protocol));
                }
            }
        }