Example #1
0
        public void CanMatch_LeadingLiteralsPattern()
        {
            HandlerMap map = new HandlerMap();
            map.Add("/test1/*", "theHandlerIWant");

            HandlerMapEntry handler = map.MapPath("/test1/test2/default.aspx");

            Assert.NotNull(handler);
            Assert.AreEqual("theHandlerIWant", handler.HandlerObjectName);
        }
        /// <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());
        }
        /// <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());
	    }