Пример #1
0
        static AbstractHandlerFactory()
        {
            PrivilegedCommand cmd = new PrivilegedCommand();

            SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), new SecurityCritical.PrivilegedCallback(cmd.Execute));
            s_simpleHandlerFactory = cmd.Result;
        }
Пример #2
0
            /// <summary>
            /// Create handler entry
            /// </summary>
            /// <param name="name"></param>
            /// <param name="factory"></param>
            /// <param name="expirationCallback"></param>
            /// <returns></returns>
            public static ActiveHandlerEntry Create(IHttpHandlerFactory factory,
                                                    string name, Action <ActiveHandlerEntry> expirationCallback)
            {
                var lifetime = factory.Create(name, out var handler);

                return(new ActiveHandlerEntry(name, handler, lifetime, expirationCallback));
            }
        /// <summary>
        /// Obtains a handler by mapping <paramref name="rawUrl"/> to the list of patterns in <paramref name="handlerMappings"/>.
        /// </summary>
        /// <param name="appContext">the application context corresponding to the current request</param>
        /// <param name="context">The <see cref="HttpContext"/> instance for this request.</param>
        /// <param name="requestType">The HTTP data transfer method (GET, POST, ...)</param>
        /// <param name="rawUrl">The requested <see cref="HttpRequest.RawUrl"/>.</param>
        /// <param name="physicalPath">The physical path of the requested resource.</param>
        /// <param name="handlerMappings"></param>
        /// <param name="handlerWithFactoryTable"></param>
        /// <returns>A handler instance for processing the current request.</returns>
        protected IHttpHandler MapHandlerInstance(IConfigurableApplicationContext appContext, HttpContext context, string requestType, string rawUrl, string physicalPath, HandlerMap handlerMappings, IDictionary handlerWithFactoryTable)
        {
            // resolve handler instance by mapping the url to the list of patterns
            HandlerMapEntry handlerMapEntry = handlerMappings.MapPath(rawUrl);

            if (handlerMapEntry == null)
            {
                throw new HttpException(404, HttpStatusCode.NotFound.ToString());
            }
            object handlerObject = appContext.GetObject(handlerMapEntry.HandlerObjectName);

            if (handlerObject is IHttpHandler)
            {
                return((IHttpHandler)handlerObject);
            }
            else if (handlerObject is IHttpHandlerFactory)
            {
                // keep a reference to the issuing factory for later ReleaseHandler call
                IHttpHandlerFactory factory = (IHttpHandlerFactory)handlerObject;
                IHttpHandler        handler = factory.GetHandler(context, requestType, rawUrl, physicalPath);
                lock (handlerWithFactoryTable.SyncRoot)
                {
                    handlerWithFactoryTable.Add(handler, factory);
                }
                return(handler);
            }

            throw new HttpException((int)HttpStatusCode.NotFound, HttpStatusCode.NotFound.ToString());
        }
 public static IHttpHandler Create(IHttpHandler httpHandler, IHttpHandlerFactory factory)
 {
     if (httpHandler is IHttpAsyncHandler)
     {
         return new AsyncHandlerWrapper((IHttpAsyncHandler) httpHandler, factory);
     }
     return new XamlHttpHandlerFactory.HandlerWrapper(httpHandler, factory);
 }
 public static IHttpHandler Create(IHttpHandler httpHandler, IHttpHandlerFactory factory)
 {
     if (httpHandler is IHttpAsyncHandler)
     {
         return(new AsyncHandlerWrapper((IHttpAsyncHandler)httpHandler, factory));
     }
     return(new XamlHttpHandlerFactory.HandlerWrapper(httpHandler, factory));
 }
Пример #6
0
            /// <summary>
            /// Create handler entry
            /// </summary>
            /// <param name="factory"></param>
            /// <param name="name"></param>
            /// <param name="expirationCallback"></param>
            /// <returns></returns>
            public static ActiveHandlerEntry Create(IHttpHandlerFactory factory,
                                                    string name, Action <ActiveHandlerEntry> expirationCallback)
            {
#pragma warning disable IDE0067 // Dispose objects before losing scope
                var lifetime = factory.Create(name, out var handler);
#pragma warning restore IDE0067 // Dispose objects before losing scope
                return(new ActiveHandlerEntry(name, handler, lifetime, expirationCallback));
            }
Пример #7
0
        /// <summary>
        /// Create factory
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="logger"></param>
        public HttpClientFactory(IHttpHandlerFactory factory, ILogger logger)
        {
            _factory = factory ?? new HttpHandlerFactory(logger);
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));

            _activeHandlers = new ConcurrentDictionary <string, ActiveHandlerEntry>(
                StringComparer.Ordinal);
            _expiredHandlers = new ConcurrentQueue <ExpiredHandlerEntry>();
        }
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IHttpHandlerFactory pageHandlerFactory = CreateFactory();

            IHttpHandler pageHandler = pageHandlerFactory.GetHandler(context, requestType, url, pathTranslated);

            BuildUpPage(pageHandler);

            return(pageHandler);
        }
        private IHttpHandlerFactory CreateFactory()
        {
            IHttpHandlerFactory pageHandlerFactory = Activator.CreateInstance(typeof(PageHandlerFactory), true) as IHttpHandlerFactory;

            if (pageHandlerFactory == null)
            {
                throw new ApplicationException("Create PageHandlerFactory failed");
            }
            return(pageHandlerFactory);
        }
Пример #10
0
        /// <summary>
        /// Same as <see cref="IHttpHandlerFactory.GetHandler"/> except the
        /// HTTP context is typed as <see cref="HttpContextBase"/> instead
        /// of <see cref="HttpContext"/>.
        /// </summary>

        public static IHttpHandler GetHandler(this IHttpHandlerFactory factory,
                                              HttpContextBase context, string requestType,
                                              string url, string pathTranslated)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            return(factory.GetHandler(context.ApplicationInstance.Context, requestType, url, pathTranslated));
        }
 /// <summary>
 /// Removes the handler from the handler/factory dictionary and releases the handler.
 /// </summary>
 /// <param name="handler">the handler to be released</param>
 /// <param name="_handlerWithFactoryTable">a dictionary containing (<see cref="IHttpHandler"/>, <see cref="IHttpHandlerFactory"/>) entries.</param>
 protected void ReleaseHandler(IHttpHandler handler, IDictionary _handlerWithFactoryTable)
 {
     lock (_handlerWithFactoryTable.SyncRoot)
     {
         IHttpHandlerFactory factory = _handlerWithFactoryTable[handler] as IHttpHandlerFactory;
         if (factory != null)
         {
             _handlerWithFactoryTable.Remove(handler);
             factory.ReleaseHandler(handler);
         }
     }
 }
 private static IHttpHandlerFactory CreatePageFactory()
 {
     if (pageFactory == null)
     {
         pageFactory = Activator.CreateInstance(typeof(PageHandlerFactory), true) as IHttpHandlerFactory;
         if (pageFactory == null)
         {
             throw new ApplicationException("无法初始化PageHandlerFactory");
         }
     }
     return pageFactory;
 }
Пример #13
0
            //This function is invoked the first time a request is made to XAMLx file
            //It caches url as key and one of the
            //following 4 as value -> "Handler/Factory/HandlerCLRType/Exception"
            IHttpHandler GetHandlerFirstTime(HttpContext context, string requestType,
                                             string url, string pathTranslated)
            {
                Type httpHandlerType;
                ConfigurationErrorsException configException;

                //GetCompiledType is costly - invoke it just once.
                //This null check is required for "error after GetCompiledType on first attempt" cases only
                if (this.hostedXamlType == null)
                {
                    this.hostedXamlType = GetCompiledCustomString(context.Request.AppRelativeCurrentExecutionFilePath);
                }

                if (XamlHostingConfiguration.TryGetHttpHandlerType(url, this.hostedXamlType, out httpHandlerType))
                {
                    if (TD.HttpHandlerPickedForUrlIsEnabled())
                    {
                        TD.HttpHandlerPickedForUrl(url, hostedXamlType.FullName, httpHandlerType.FullName);
                    }
                    if (typeof(IHttpHandler).IsAssignableFrom(httpHandlerType))
                    {
                        IHttpHandler handler = (IHttpHandler)CreateInstance(httpHandlerType);
                        if (handler.IsReusable)
                        {
                            this.cachedResult = handler;
                        }
                        else
                        {
                            this.cachedResult = httpHandlerType;
                        }
                        return(handler);
                    }
                    else if (typeof(IHttpHandlerFactory).IsAssignableFrom(httpHandlerType))
                    {
                        IHttpHandlerFactory factory = (IHttpHandlerFactory)CreateInstance(httpHandlerType);
                        this.cachedResult = factory;
                        IHttpHandler handler = factory.GetHandler(context, requestType, url, pathTranslated);
                        return(HandlerWrapper.Create(handler, factory));
                    }
                    else
                    {
                        configException =
                            new ConfigurationErrorsException(SR.NotHttpHandlerType(url, this.hostedXamlType, httpHandlerType.FullName));
                        this.cachedResult = configException;
                        throw FxTrace.Exception.AsError(configException);
                    }
                }
                configException =
                    new ConfigurationErrorsException(SR.HttpHandlerForXamlTypeNotFound(url, this.hostedXamlType, XamlHostingConfiguration.XamlHostingSection));
                this.cachedResult = configException;
                throw FxTrace.Exception.AsError(configException);
            }
Пример #14
0
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IHttpHandlerFactory pageFactory = CreatePageFactory();
            IHttpHandler        handler     = pageFactory.GetHandler(context, requestType, url, pathTranslated);

            handler = Build(handler);
            Page page = handler as Page;

            if (page != null)
            {
                page.Init += new EventHandler(Page_Init);
            }
            return(page);
        }
Пример #15
0
        public void ProcessRequest(HttpContext context)
        {
            IHttpHandlerFactory fact    = (IHttpHandlerFactory)Activator.CreateInstance(Type.GetType("System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"));
            IHttpHandler        handler = fact.GetHandler(context, context.Request.RequestType, context.Request.Path, context.Request.PhysicalApplicationPath);

            try
            {
                handler.ProcessRequest(context);
                context.Response.StatusCode = 200;
                context.ApplicationInstance.CompleteRequest();
            }
            finally
            {
                fact.ReleaseHandler(handler);
            }
        }
 internal HandlerFactoryCache(HttpHandlerAction mapping)
 {
     object obj2 = mapping.Create();
     if (obj2 is IHttpHandler)
     {
         this._factory = new HandlerFactoryWrapper((IHttpHandler) obj2, this.GetHandlerType(mapping));
     }
     else
     {
         if (!(obj2 is IHttpHandlerFactory))
         {
             throw new HttpException(System.Web.SR.GetString("Type_not_factory_or_handler", new object[] { obj2.GetType().FullName }));
         }
         this._factory = (IHttpHandlerFactory) obj2;
     }
 }
        internal HandlerFactoryCache(HttpHandlerAction mapping) {
            Object instance = mapping.Create();

            // make sure it is either handler or handler factory

            if (instance is IHttpHandler) {
                // create bogus factory around it
                _factory = new HandlerFactoryWrapper((IHttpHandler)instance, GetHandlerType(mapping));
            }
            else if (instance is IHttpHandlerFactory) {
                _factory = (IHttpHandlerFactory)instance;
            }
            else {
                throw new HttpException(SR.GetString(SR.Type_not_factory_or_handler, instance.GetType().FullName));
            }
        }
Пример #18
0
 public static void BCLPageHandlerFactoryBehaviorImpl()
 {
     using (TestWebContext ctx = new TestWebContext("/Test", "DoesNotExist.oaspx"))
     {
         try
         {
             IHttpHandlerFactory phf = (IHttpHandlerFactory)Activator.CreateInstance(typeof(System.Web.UI.Page).Assembly.GetType("System.Web.UI.PageHandlerFactory"), true);
             phf.GetHandler(HttpContext.Current, "GET", ctx.HttpWorkerRequest.GetFilePath(), ctx.HttpWorkerRequest.GetFilePathTranslated());
         }
         catch (HttpException e)
         {
             Assert.AreEqual(404, e.GetHttpCode());
             Assert.IsTrue(e.Message.IndexOf(ctx.HttpWorkerRequest.GetFilePath()) > 0);
         }
     }
 }
Пример #19
0
        internal HandlerFactoryCache(HttpHandlerAction mapping)
        {
            object obj2 = mapping.Create();

            if (obj2 is IHttpHandler)
            {
                this._factory = new HandlerFactoryWrapper((IHttpHandler)obj2, this.GetHandlerType(mapping));
            }
            else
            {
                if (!(obj2 is IHttpHandlerFactory))
                {
                    throw new HttpException(System.Web.SR.GetString("Type_not_factory_or_handler", new object[] { obj2.GetType().FullName }));
                }
                this._factory = (IHttpHandlerFactory)obj2;
            }
        }
 private IHttpHandler GetHandlerSubSequent(HttpContext context, string requestType, string url, string pathTranslated)
 {
     if (this.cachedResult is IHttpHandler)
     {
         return((IHttpHandler)this.cachedResult);
     }
     if (this.cachedResult is IHttpHandlerFactory)
     {
         IHttpHandlerFactory cachedResult = (IHttpHandlerFactory)this.cachedResult;
         return(XamlHttpHandlerFactory.HandlerWrapper.Create(cachedResult.GetHandler(context, requestType, url, pathTranslated), cachedResult));
     }
     if (!(this.cachedResult is Type))
     {
         throw FxTrace.Exception.AsError((ConfigurationErrorsException)this.cachedResult);
     }
     return((IHttpHandler)XamlHttpHandlerFactory.CreateInstance((Type)this.cachedResult));
 }
Пример #21
0
        internal HandlerFactoryCache(HttpHandlerAction mapping)
        {
            Object instance = mapping.Create();

            // make sure it is either handler or handler factory

            if (instance is IHttpHandler)
            {
                // create bogus factory around it
                _factory = new HandlerFactoryWrapper((IHttpHandler)instance, GetHandlerType(mapping));
            }
            else if (instance is IHttpHandlerFactory)
            {
                _factory = (IHttpHandlerFactory)instance;
            }
            else
            {
                throw new HttpException(SR.GetString(SR.Type_not_factory_or_handler, instance.GetType().FullName));
            }
        }
Пример #22
0
        internal HandlerFactoryCache(string type)
        {
            Object instance = Create(type);

            // make sure it is either handler or handler factory

            if (instance is IHttpHandler)
            {
                // create bogus factory around it
                _factory = new HandlerFactoryWrapper((IHttpHandler)instance, GetHandlerType(type));
            }
            else if (instance is IHttpHandlerFactory)
            {
                _factory = (IHttpHandlerFactory)instance;
            }
            else
            {
                throw new HttpException(SR.GetString(SR.Type_not_factory_or_handler, instance.GetType().FullName));
            }
            TelemetryLogger.LogHttpHandler(instance.GetType());
        }
            private IHttpHandler GetHandlerFirstTime(HttpContext context, string requestType, string url, string pathTranslated)
            {
                Type type;
                ConfigurationErrorsException exception;

                if (this.hostedXamlType == null)
                {
                    this.hostedXamlType = this.GetCompiledCustomString(context.Request.AppRelativeCurrentExecutionFilePath);
                }
                if (XamlHostingConfiguration.TryGetHttpHandlerType(url, this.hostedXamlType, out type))
                {
                    if (TD.HttpHandlerPickedForUrlIsEnabled())
                    {
                        TD.HttpHandlerPickedForUrl(url, this.hostedXamlType.FullName, type.FullName);
                    }
                    if (typeof(IHttpHandler).IsAssignableFrom(type))
                    {
                        IHttpHandler handler = (IHttpHandler)XamlHttpHandlerFactory.CreateInstance(type);
                        if (handler.IsReusable)
                        {
                            this.cachedResult = handler;
                            return(handler);
                        }
                        this.cachedResult = type;
                        return(handler);
                    }
                    if (typeof(IHttpHandlerFactory).IsAssignableFrom(type))
                    {
                        IHttpHandlerFactory factory = (IHttpHandlerFactory)XamlHttpHandlerFactory.CreateInstance(type);
                        this.cachedResult = factory;
                        return(XamlHttpHandlerFactory.HandlerWrapper.Create(factory.GetHandler(context, requestType, url, pathTranslated), factory));
                    }
                    exception         = new ConfigurationErrorsException(System.Xaml.Hosting.SR.NotHttpHandlerType(url, this.hostedXamlType, type.FullName));
                    this.cachedResult = exception;
                    throw FxTrace.Exception.AsError(exception);
                }
                exception         = new ConfigurationErrorsException(System.Xaml.Hosting.SR.HttpHandlerForXamlTypeNotFound(url, this.hostedXamlType, "system.xaml.hosting/httpHandlers"));
                this.cachedResult = exception;
                throw FxTrace.Exception.AsError(exception);
            }
Пример #24
0
 //This function retrievs the cached object and uses it to get handler or exception
 IHttpHandler GetHandlerSubSequent(HttpContext context, string requestType,
                                   string url, string pathTranslated)
 {
     if (this.cachedResult is IHttpHandler)
     {
         return((IHttpHandler)this.cachedResult);
     }
     else if (this.cachedResult is IHttpHandlerFactory)
     {
         IHttpHandlerFactory factory = ((IHttpHandlerFactory)this.cachedResult);
         IHttpHandler        handler = factory.GetHandler(context, requestType, url, pathTranslated);
         return(HandlerWrapper.Create(handler, factory));
     }
     else if (this.cachedResult is Type)
     {
         return((IHttpHandler)CreateInstance((Type)this.cachedResult));
     }
     else
     {
         throw FxTrace.Exception.AsError((ConfigurationErrorsException)this.cachedResult);
     }
 }
Пример #25
0
		//
		// Invoked at the end of the pipeline execution
		//
		void PipelineDone ()
		{
			try {
				if (EndRequest != null)
					EndRequest (this, EventArgs.Empty);
			} catch (Exception e){
				ProcessError (e);
			}

			try {

				OutputPage ();
			} catch (Exception e) {
				Console.WriteLine ("Internal error: OutputPage threw an exception " + e);
			} finally {
				context.WorkerRequest.EndOfRequest();
				if (begin_iar != null){
					try {
						begin_iar.Complete ();
					} catch {
						//
						// TODO: if this throws an error, we have no way of reporting it
						// Not really too bad, since the only failure might be
						// `HttpRuntime.request_processed'
						//
					}
				}
				
				done.Set ();

				if (factory != null && context.Handler != null){
					factory.ReleaseHandler (context.Handler);
					factory = null;
				}
				
				context.Handler = null;
				// context = null; -> moved to PostDone
				pipeline = null;
				current_ai = null;
			}
			PostDone ();
		}
        public void ReleaseHandler(IHttpHandler handler)
        {
            IHttpHandlerFactory pageHandlerFactory = CreateFactory();

            pageHandlerFactory.ReleaseHandler(handler);
        }
 internal HandlerWithFactory(IHttpHandler handler, IHttpHandlerFactory factory)
 {
     this._handler = handler;
     this._factory = factory;
 }
Пример #28
0
 public WabHttpHandler(IHttpHandlerFactory handlerFactory, IEncoderFactory encoderFactory, IResponseWriterFactory writerFactory)
 {
     this.handlerFactory = handlerFactory;
     this.encoderFactory = encoderFactory;
     this.writerFactory = writerFactory;
 }
Пример #29
0
 // Methods
 internal HandlerWrapper(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
 {
     this._originalFactory = originalFactory;
     this._originalHandler = originalHandler;
 }
 public AsyncHandlerWrapperWithSession(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
     : base(originalHandler, originalFactory) { }
Пример #31
0
 /// <summary>
 /// Create a new instance, using <paramref name="innerFactory"/> as underlying factory.
 /// </summary>
 /// <param name="innerFactory">the factory to be wrapped.</param>
 public DefaultHandlerFactory(IHttpHandlerFactory innerFactory)
 {
     AssertUtils.ArgumentNotNull(innerFactory, "innerFactory");
     _innerFactory = innerFactory;
 }
 private HandlerWrapper(IHttpHandler httpHandler, IHttpHandlerFactory factory)
 {
     this.httpHandler = httpHandler;
     this.factory = factory;
 }
 public AsyncHandlerWrapperWithSession(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
     : base(originalHandler, originalFactory)
 {
 }
Пример #34
0
    public void Execute()
    {
        Type handlerFactoryType = typeof(IHttpHandler).Assembly.GetType("System.Web.UI.WebServiceHandlerFactory");

        Result = (IHttpHandlerFactory)Activator.CreateInstance(handlerFactoryType, true);
    }
 public HandlerWrapper(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
 {
     _originalFactory = originalFactory;
     _originalHandler = originalHandler;
 }
Пример #36
0
 internal AsyncHandlerWrapper(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
     :
     base(originalHandler, originalFactory)
 {
 }
 public ScriptHandlerFactory()
 {
     //_restHandlerFactory = new RestHandlerFactory();
     
     _webServiceHandlerFactory = new System.Web.Services.Protocols.WebServiceHandlerFactory();
 }
Пример #38
0
		// Used by HttpServerUtility.Execute
		internal IHttpHandler GetHandler (HttpContext context)
		{
			HttpRequest request = context.Request;
			string verb = request.RequestType;
			string url = request.FilePath;
			
			IHttpHandler handler = null;
#if NET_2_0
			HttpHandlersSection section = (HttpHandlersSection) WebConfigurationManager.GetSection ("system.web/httpHandlers");
			object o = section.LocateHandler (verb, url);
#else
			HandlerFactoryConfiguration factory_config = (HandlerFactoryConfiguration) HttpContext.GetAppConfig ("system.web/httpHandlers");
			object o = factory_config.LocateHandler (verb, url);
#endif

			factory = o as IHttpHandlerFactory;
			
			if (factory == null) {
				handler = (IHttpHandler) o;
			} else {
				handler = factory.GetHandler (context, verb, url, request.PhysicalPath);
			}
			context.Handler = handler;

			return handler;
		}
 static AbstractHandlerFactory()
 {
     PrivilegedCommand cmd = new PrivilegedCommand();
     SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), new SecurityCritical.PrivilegedCallback(cmd.Execute));
     s_simpleHandlerFactory = cmd.Result;
 }
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {

            IHttpHandler HttpHandler = null;

            try
            {
                // Request Hosting permissions
                new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand();

                // Try to get the type associated with the request (On a name to type basis)
                Type WebServiceType = this.GetServiceType(Path.GetFileNameWithoutExtension(pathTranslated));

                // if we did not find any send it on to the original ajax script service handler.
                if (WebServiceType == null)
                {
                    // [REFLECTION] Get the internal class System.Web.Script.Services.ScriptHandlerFactory create it.
                    IHttpHandlerFactory ScriptHandlerFactory = (IHttpHandlerFactory)System.Activator.CreateInstance(AjaxAssembly.GetType("System.Web.Script.Services.ScriptHandlerFactory"));
                    _usedHandlerFactory = ScriptHandlerFactory;
                    return ScriptHandlerFactory.GetHandler(context, requestType, url, pathTranslated);
                }

                // [REFLECTION] get the Handlerfactory : RestHandlerFactory (Handles Javascript proxy Generation and actions)
                IHttpHandlerFactory JavascriptHandlerFactory = (IHttpHandlerFactory)System.Activator.CreateInstance(AjaxAssembly.GetType("System.Web.Script.Services.RestHandlerFactory"));

                // [REFLECTION] Check if the current request is a Javasacript method
                // JavascriptHandlerfactory.IsRestRequest(context);
                System.Reflection.MethodInfo IsScriptRequestMethod = JavascriptHandlerFactory.GetType().GetMethod("IsRestRequest", BindingFlags.Static | BindingFlags.NonPublic);
                if ((bool)IsScriptRequestMethod.Invoke(null, new object[] { context }))
                {
                    // Remember the used factory for later in ReleaseHandler
                    _usedHandlerFactory = JavascriptHandlerFactory;

                    // Check and see if it is a Javascript Request or a request for a Javascript Proxy.
                    bool IsJavascriptDebug = string.Equals(context.Request.PathInfo, "/jsdebug", StringComparison.OrdinalIgnoreCase);
                    bool IsJavascript = string.Equals(context.Request.PathInfo, "/js", StringComparison.OrdinalIgnoreCase);
                    if (IsJavascript || IsJavascriptDebug)
                    {

                        // [REFLECTION] fetch the constructor for the WebServiceData Object
                        ConstructorInfo WebServiceDataConstructor = AjaxAssembly.GetType("System.Web.Script.Services.WebServiceData").GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Type), typeof(bool) }, null);

                        // [REFLECTION] fetch the constructor for the WebServiceClientProxyGenerator
                        ConstructorInfo WebServiceClientProxyGeneratorConstructor = AjaxAssembly.GetType("System.Web.Script.Services.WebServiceClientProxyGenerator").GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(bool) }, null);

                        // [REFLECTION] get the method from WebServiceClientProxy to create the javascript : GetClientProxyScript
                        MethodInfo GetClientProxyScriptMethod = AjaxAssembly.GetType("System.Web.Script.Services.ClientProxyGenerator").GetMethod("GetClientProxyScript", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { AjaxAssembly.GetType("System.Web.Script.Services.WebServiceData") }, null);

                        // [REFLECTION] We invoke : 
                        // new WebServiceClientProxyGenerator(url,false).WebServiceClientProxyGenerator.GetClientProxyScript(new WebServiceData(WebServiceType));
                        string Javascript = (string)GetClientProxyScriptMethod.Invoke(
                          WebServiceClientProxyGeneratorConstructor.Invoke(new Object[] { url, IsJavascriptDebug })
                        , new Object[] {
                            WebServiceDataConstructor.Invoke(new object[] { WebServiceType, false }) 
                            }
                        );

                        // The following caching code was copied from the original assembly, read with Reflector, comments were added manualy.
                        #region Caching

                        // Check the assembly modified time and use it as caching http header
                        DateTime AssemblyModifiedDate = GetAssemblyModifiedTime(WebServiceType.Assembly);

                        // See "if Modified since" was requested in the http headers, and check it with the assembly modified time
                        string s = context.Request.Headers["If-Modified-Since"];

                        DateTime TempDate;
                        if (((s != null) && DateTime.TryParse(s, out TempDate)) && (TempDate >= AssemblyModifiedDate))
                        {
                            context.Response.StatusCode = 0x130;
                            return null;
                        }

                        // Add HttpCaching data to the http headers
                        if (!IsJavascriptDebug && (AssemblyModifiedDate.ToUniversalTime() < DateTime.UtcNow))
                        {
                            HttpCachePolicy cache = context.Response.Cache;
                            cache.SetCacheability(HttpCacheability.Public);
                            cache.SetLastModified(AssemblyModifiedDate);
                        }
                        #endregion

                        // Set Add the javascript to a new custom handler and set it in HttpHandler.
                        HttpHandler = new JavascriptProxyHandler(Javascript);
                        return HttpHandler;
                    }
                    else
                    {
                        IHttpHandler JavascriptHandler = (IHttpHandler)System.Activator.CreateInstance(AjaxAssembly.GetType("System.Web.Script.Services.RestHandler"));

                        // [REFLECTION] fetch the constructor for the WebServiceData Object
                        ConstructorInfo WebServiceDataConstructor = AjaxAssembly.GetType("System.Web.Script.Services.WebServiceData").GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Type), typeof(bool) }, null);

                        // [REFLECTION] get method : JavaScriptHandler.CreateHandler
                        MethodInfo CreateHandlerMethod = JavascriptHandler.GetType().GetMethod("CreateHandler", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { AjaxAssembly.GetType("System.Web.Script.Services.WebServiceData"), typeof(string) }, null);

                        // [REFLECTION] Invoke CreateHandlerMethod :
                        // HttpHandler = JavaScriptHandler.CreateHandler(WebServiceType,false);
                        HttpHandler = (IHttpHandler)CreateHandlerMethod.Invoke(JavascriptHandler, new Object[]
                                {
                                    WebServiceDataConstructor.Invoke(new object[] { WebServiceType, false })
                                ,   context.Request.PathInfo.Substring(1)
                                }
                        );
                    }
                    return HttpHandler;
                }
                else
                {
                    // Remember the used factory for later in ReleaseHandler
                    IHttpHandlerFactory WebServiceHandlerFactory = new WebServiceHandlerFactory();
                    _usedHandlerFactory = WebServiceHandlerFactory;

                    // [REFLECTION] Get the method CoreGetHandler
                    MethodInfo CoreGetHandlerMethod = _usedHandlerFactory.GetType().GetMethod("CoreGetHandler", BindingFlags.NonPublic | BindingFlags.Instance);

                    // [REFLECTION] Invoke the method CoreGetHandler :
                    // WebServiceHandlerFactory.CoreGetHandler(WebServiceType,context,context.Request, context.Response);
                    HttpHandler = (IHttpHandler)CoreGetHandlerMethod.Invoke(_usedHandlerFactory, new object[]
{
    WebServiceType, context, context.Request, context.Response
}
                    );
                    return HttpHandler;
                }
            }
            // Because we are using Reflection, errors generated in reflection will be an InnerException, 
            // to get the real Exception we throw the InnerException it.
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
 public void Execute()
 {
     Type simpleHandlerFactoryType = typeof(IHttpHandler).Assembly.GetType("System.Web.UI.SimpleHandlerFactory");
     Result = (IHttpHandlerFactory)Activator.CreateInstance(simpleHandlerFactoryType, true);
 }
 public AsyncHandlerWrapper(IHttpAsyncHandler httpAsyncHandler, IHttpHandlerFactory factory)
     : base(httpAsyncHandler, factory)
 {
     this.httpAsyncHandler = httpAsyncHandler;
 }
 internal HandlerWithFactory(IHttpHandler handler, IHttpHandlerFactory factory) {
     _handler = handler;
     _factory = factory;
 }
        public ScriptHandlerFactory()
        {
            //_restHandlerFactory = new RestHandlerFactory();

            _webServiceHandlerFactory = new System.Web.Services.Protocols.WebServiceHandlerFactory();
        }
 public AsyncHandlerWrapper(IHttpAsyncHandler httpAsyncHandler, IHttpHandlerFactory factory) : base(httpAsyncHandler, factory)
 {
     this.httpAsyncHandler = httpAsyncHandler;
 }
			public HandlerFactory (IHttpHandler handler, IHttpHandlerFactory factory) 
			{
				this.Handler = handler;
				this.Factory = factory;
			}
 internal AsyncHandlerWrapper(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
     :
     base(originalHandler, originalFactory) { }
Пример #48
0
 /// <summary>
 /// Create a new instance, using <paramref name="innerFactory"/> as underlying factory.
 /// </summary>
 /// <param name="innerFactory">the factory to be wrapped.</param>
 public DefaultHandlerFactory(IHttpHandlerFactory innerFactory)
 {
     AssertUtils.ArgumentNotNull(innerFactory, "innerFactory");
     _innerFactory = innerFactory;
 }
 public HandlerWrapper(IHttpHandler originalHandler, IHttpHandlerFactory originalFactory)
 {
     _originalFactory = originalFactory;
     _originalHandler = originalHandler;
 }