Esempio n. 1
0
        public void GetVirtualPath_WithIgnoreRoute_AlwaysReturnsNull()
        {
            //arrange
            var httpContext    = new Mock <HttpContextBase>();
            var requestContext = new RequestContext(httpContext.Object, new RouteData());
            var route          = new IgnoreRoute("{*catchall}");

            //act
            VirtualPathData virtualPath = route.GetVirtualPath(requestContext, new RouteValueDictionary());

            //assert
            Assert.IsNull(virtualPath);
        }
Esempio n. 2
0
        private static void MapIgnoreRoute(RouteCollection routes, string url, RouteValueDictionary constraints)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            IgnoreRoute ignore = new IgnoreRoute(url);

            ignore.Constraints = constraints;
            routes.Add(ignore);
        }
        void IHttpModule.Init(HttpApplication application)
        {
            // Here we update ASP.NET MVC routing table to avoid processing of WebDAV requests.
            // This should be done only one time during web application start event.

            lock (appStartLock)
            {
                if (appStarted)
                {
                    return;
                }
                appStarted = true;
            }

            NameValueCollection davLocationsSection = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("davLocations");

            int routeInsertPosition = 0;

            foreach (string path in davLocationsSection.AllKeys)
            {
                string   verbs   = davLocationsSection[path];
                string[] methods = verbs.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                                   .Select(verb => verb.Trim().ToUpper()).ToArray();

                string prefix          = path.Trim(new[] { '/', '\\' });
                string ignoreRoutePath = (prefix == string.Empty ? string.Empty : prefix + "/") + "{*rest}";

                IgnoreRoute ignoreRoute = new IgnoreRoute(ignoreRoutePath);
                if (methods.Length > 0)
                {
                    ignoreRoute.Constraints = new RouteValueDictionary {
                        { "httpMethod", new HttpMethodConstraint(methods) }
                    };
                }
                RouteTable.Routes.Insert(routeInsertPosition++, ignoreRoute);
            }
        }
 public IgnoreRouteTests()
 {
     middleware = new IgnoreRoute(next: (initialContext) => Task.FromResult(0), new List <string> {
         "favicon.ico"
     });
 }