示例#1
0
        public static void RegisterRoutes(HttpRouteCollection routes)
        {
            routes.IgnoreRoute("Html", "{whatever}.html/{*pathInfo}");
            routes.IgnoreRoute("FilesRoute", "app/{*pathInfo}");

            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { controller = "Default",
                                action     = "Get", id = RouteParameter.Optional }
                );
        }
示例#2
0
        public static void RegisterRoutes(HttpRouteCollection routes)
        {
            routes.IgnoreRoute("Html", "{whatever}.html/{*pathInfo}");
            routes.IgnoreRoute("FilesRoute", "app/{*pathInfo}");

            routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "{controller}/{action}/{id}",
                    defaults: new { controller = "Default",
                        action = "Get", id = RouteParameter.Optional }
                );
        }
 internal HttpRouterConfigurator IgnoreRoute(string name, string route)
 {
     routes.IgnoreRoute(name, route);
     return(this);
 }
示例#4
0
        /// <summary>
        /// Routes are mapped such that urls generated are lowercase
        /// </summary>
        /// <param name="routes"></param>
        public static void RegisterRoutes(HttpRouteCollection routes)
        {
            //NB: ic === "institution code"; ver === "version"
            string instCode = "Core";

            routes.IgnoreRoute(routeName: "resources", routeTemplate: "{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("static", "{ *staticfile}", new { staticfile = @".*\.(css|less|sass|js|gif|png|jpg|jpeg|ico|svg|ttf|eot|woff|woff2|xml|csv|txt|map|json|pdf|doc|docx|xls|xlsx|dll|exe|pdb)(/.*)?" });

            // From most specific to most general
            routes.MapHttpRoute( //LowerCase(
                name: "Api_Default",
                routeTemplate: "api/",
                defaults: new { ver = "1.0", ic = instCode, area = "", controller = "Home", action = "Index", id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );

            routes.MapHttpRoute( //LowerCase(
                name: "Api_DefaultApi",
                routeTemplate: "api/{ver}/",
                defaults: new { ic = instCode, area = "", controller = "Home", action = "Index", id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );

            routes.MapHttpRoute( //LowerCase(
                name: "Api_Error",
                routeTemplate: "api/{ver}/Error",
                defaults: new { ic = instCode, area = "", controller = "Error", action = "Index", id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );

            routes.MapHttpRoute( //LowerCase(
                name: "Api_TenantError",
                routeTemplate: "api/{ver}/{ic}/Error",
                defaults: new { area = "", controller = "Error", action = "Index", id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );

            routes.MapHttpRoute( //LowerCase(
                name: "Api_IcOnly",
                routeTemplate: "api/{ver}/{ic}",
                defaults: new { area = "", controller = "Home", action = "Index", id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );

            // Ambigous; this clashes with the below a lot of times
            //routes.MapHttpRoute( //LowerCase(
            //    name: "Api_ControllerAndActionOnly",
            //    routeTemplate: "api/{ver}/{controller}/{action}/{id}",
            //    defaults: new { ic = instCode, area = "", id = RouteParameter.Optional },
            //    constraints: new { id = @"\d*" }
            //);

            routes.MapHttpRoute( //LowerCase(
                name: "Api_MultiTenant",
                routeTemplate: "api/{ver}/{ic}/{controller}/{action}/{id}",
                defaults: new { area = "", id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );

            routes.MapHttpRoute( //LowerCase(
                name: "Api_MultiTenantWithArea",
                routeTemplate: "api/{ver}/{ic}/{area}/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: new { id = @"\d*" }
                );
        }
        public void IgnoreRouteInternalNeverMatchesUrlGeneration()
        {
            // Arrange
            HttpRouteCollection routes = new HttpRouteCollection();
            IHttpRoute route = routes.IgnoreRoute("Foo", "SomeRouteTemplate");

            // Act
            IHttpVirtualPathData vpd = route.GetVirtualPath(new HttpRequestMessage(HttpMethod.Get, "SomeRouteTemplate"), null);

            // Assert
            Assert.Null(vpd);
        }
        public void IgnoreRouteWithConstraints()
        {
            // Arrange
            HttpRouteCollection routes = new HttpRouteCollection();
            var constraints = new { Foo = "DefaultFoo" };

            // Act
            routes.IgnoreRoute("SomeRouteName", "SomeRouteTemplate", constraints);

            // Assert
            HttpRoute route = Assert.Single(routes.Cast<HttpRoute>());
            Assert.NotNull(route);
            Assert.Equal("SomeRouteTemplate", route.RouteTemplate);
            Assert.IsType<StopRoutingHandler>(route.Handler);
            Assert.True(route.Defaults.Count == 0);
            Assert.Single(route.Constraints);
            Assert.Equal("DefaultFoo", route.Constraints["Foo"]);
        }
        public void IgnoreRouteWithNullUrlThrows()
        {
            // Arrange
            HttpRouteCollection routes = new HttpRouteCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { routes.IgnoreRoute("foo", null); },
                "routeTemplate");
        }
        public void IgnoreRouteWithNullRouteNameThrows()
        {
            // Arrange
            HttpRouteCollection routes = new HttpRouteCollection();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                delegate { routes.IgnoreRoute(null, "foo"); },
                "routeName");
        }
示例#9
0
文件: Program.cs 项目: monsterNY/vlxm
 /// <summary>忽略指定的路由。</summary>
 /// <returns>返回 <see cref="T:System.Web.Http.Routing.IHttpRoute" />。</returns>
 /// <param name="routes">应用程序的路由的集合。</param>
 /// <param name="routeName">要忽略的路由的名称。</param>
 /// <param name="routeTemplate">路由的路由模板。</param>
 public static IHttpRoute IgnoreRoute(this HttpRouteCollection routes, string routeName, string routeTemplate)
 {
     return(routes.IgnoreRoute(routeName, routeTemplate, (object)null));
 }