当前位置: 首页>>代码示例>>C#>>正文


C# HttpRouteCollection类代码示例

本文整理汇总了C#中HttpRouteCollection的典型用法代码示例。如果您正苦于以下问题:C# HttpRouteCollection类的具体用法?C# HttpRouteCollection怎么用?C# HttpRouteCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpRouteCollection类属于命名空间,在下文中一共展示了HttpRouteCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Match_UsesODataDefaultRoutingConventions_IfControllerFound

        public void Match_UsesODataDefaultRoutingConventions_IfControllerFound(string expectedControllerName,
            string entitySetName)
        {
            // Arrange
            const string routeName = "api";
            var request = new HttpRequestMessage(HttpMethod.Get, "http://any/" + entitySetName);
            var routeCollection = new HttpRouteCollection { { routeName, new HttpRoute() } };
            var config = new HttpConfiguration(routeCollection);
            request.SetConfiguration(config);
            var pathHandler = new DefaultODataPathHandler();
            var model = GetEdmModel();
            config.MapHttpAttributeRoutes();
            var conventions = config.CreateODataDomainRoutingConventions<NorthwindDomainController>(model);
            var constraint = new DefaultODataPathRouteConstraint(pathHandler, model, routeName, conventions);
            config.EnsureInitialized();
            var values = new Dictionary<string, object>
            {
                { ODataRouteConstants.ODataPath, entitySetName },
            };

            // Act
            var matched = constraint.Match(request, route: null, parameterName: null, values: values,
                routeDirection: HttpRouteDirection.UriResolution);

            // Assert
            Assert.True(matched);
            Assert.Equal(expectedControllerName, values[ODataRouteConstants.Controller]);
        }
开发者ID:workjie,项目名称:RESTier,代码行数:28,代码来源:DefaultODataPathRouteConstraintTest.cs

示例2: RegisterRoutes

 public static void RegisterRoutes(HttpRouteCollection routes)
 {
     routes.MapHttpRoute("BeersRoute", "beers/{id}", new { controller = "Beer" }); // this one is needed only because beers vs. 1 beer are separated into 2 controllers
     routes.MapHttpRoute("DefaultApi", "{controller}/{id}", new { id = RouteParameter.Optional });
     routes.MapHttpRoute("BreweryBeersRoute", "breweries/{id}/beers", new { controller = "BeersFromBrewery" });
     routes.MapHttpRoute("StyleBeersRoute", "styles/{id}/beers", new { controller = "BeersFromStyle" });
 }
开发者ID:AndreasKorn,项目名称:WebApi.Hal,代码行数:7,代码来源:RouteConfig.cs

示例3: RegisterRoutes

 private static void RegisterRoutes( HttpRouteCollection routes )
 {
     routes.MapHttpRoute( "Info", "", new { controller = "Game", action = "Info" } );
       routes.MapHttpRoute( "User", "User", new { controller = "User" } );
       routes.MapHttpRoute( "Game", "{action}", new { controller = "Game" } );
       routes.MapHttpRoute( "Default", "{controller}/{action}" );
 }
开发者ID:h2h,项目名称:HelloWorld,代码行数:7,代码来源:Global.asax.cs

示例4: Configure

 private void Configure(HttpRouteCollection routes)
 {
     routes.MapHttpRoute(
     "DefaultApiWithId",
     "Api/TestDependency",
     new { controller = "TestDependency" });
 }
开发者ID:Zero1991,项目名称:Topshelf.Integrations,代码行数:7,代码来源:TopshelfWebApiNinjectTests.cs

示例5: RegisterRoutes

 public static void RegisterRoutes(HttpRouteCollection routes)
 {
     routes.MapHttpRoute(
         name: "DefaultApi",
         routeTemplate: "api/{controller}/{id}",
         defaults: new { id = RouteParameter.Optional });
 }
开发者ID:youtao,项目名称:WebAPI-Learn,代码行数:7,代码来源:RouteConfig.cs

示例6: AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints

        public void AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints()
        {
            // Arrange
            HttpRouteCollection routes = new HttpRouteCollection();
            IEdmModel model = new EdmModel();
            string routeName = "name";
            string routePrefix = "prefix";
            var pathHandler = new DefaultODataPathHandler();
            var conventions = new List<IODataRoutingConvention>();

            // Act
            routes.MapODataServiceRoute(routeName, routePrefix, model, pathHandler, conventions);

            // Assert
            IHttpRoute odataRoute = routes[routeName];
            Assert.Single(routes);
            Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate);
            Assert.Equal(2, odataRoute.Constraints.Count);

            var odataPathConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataPathRouteConstraint>());
            Assert.Same(model, odataPathConstraint.EdmModel);
            Assert.IsType<DefaultODataPathHandler>(odataPathConstraint.PathHandler);
            Assert.NotNull(odataPathConstraint.RoutingConventions);

            var odataVersionConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataVersionConstraint>());
            Assert.Equal(ODataVersion.V1, odataVersionConstraint.MinVersion);
            Assert.Equal(ODataVersion.V3, odataVersionConstraint.MaxVersion);
        }
开发者ID:shailendra9,项目名称:WebApi,代码行数:28,代码来源:HttpRouteCollectionExtensionsTest.cs

示例7: HttpRouteCollection_Dispose_UniquifiesHandlers

        public void HttpRouteCollection_Dispose_UniquifiesHandlers()
        {
            // Arrange
            var collection = new HttpRouteCollection();

            var handler1 = new Mock<HttpMessageHandler>();
            handler1.Protected().Setup("Dispose", true).Verifiable();

            var handler2 = new Mock<HttpMessageHandler>();
            handler1.Protected().Setup("Dispose", true).Verifiable();

            var route1 = new Mock<IHttpRoute>();
            route1.SetupGet(r => r.Handler).Returns(handler1.Object);

            var route2 = new Mock<IHttpRoute>();
            route2.SetupGet(r => r.Handler).Returns(handler1.Object);

            var route3 = new Mock<IHttpRoute>();
            route3.SetupGet(r => r.Handler).Returns(handler2.Object);

            collection.Add("route1", route1.Object);
            collection.Add("route2", route2.Object);
            collection.Add("route3", route3.Object);

            // Act
            collection.Dispose();

            // Assert
            handler1.Protected().Verify("Dispose", Times.Once(), true);
            handler2.Protected().Verify("Dispose", Times.Once(), true);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:31,代码来源:HttpRouteCollectionTest.cs

示例8: Test

		public void Test()
		{
			//var apiExplorer = new Mock<IApiExplorer>();
			//var apiDescriptions = new Collection<ApiDescription>();
			//var httpConfiguration = new HttpConfiguration();
			//var actionDescriptor =
			//	new ReflectedHttpActionDescriptor(
			//		new HttpControllerDescriptor(httpConfiguration, typeof (TestController).Name, typeof (TestController)),
			//		new TestController().GetType().GetMethod("Get"));
			//var apiDescriptionMock = new Mock<ApiDescription>();
			//apiDescriptionMock.Setup(x => x.ResponseDescription).Returns(new ResponseDescription());
			//apiDescriptionMock.Setup(x => x.ActionDescriptor).Returns(actionDescriptor);
			//apiDescriptionMock.Setup(x => x.RelativePath).Returns("test");
			//apiDescriptionMock.Setup(x => x.Route).Returns(new HttpRoute("test/{id}"));
			//apiDescriptions.Add(apiDescriptionMock.Object);
			//apiExplorer.Setup(x => x.ApiDescriptions).Returns(apiDescriptions);

			var routes = new HttpRouteCollection();
			routes.Add("test", new HttpRoute("test/{id}"));
			var conf = new HttpConfiguration(routes);
			var apiExplorer = conf.Services.GetApiExplorer();
			var apiExplorerService = new ApiExplorerService(apiExplorer, "http://test.com");
			var ramlDoc = apiExplorerService.GetRaml();
			Assert.IsNotNull(ramlDoc);
		}
开发者ID:Kristinn-Stefansson,项目名称:raml-dotnet-tools,代码行数:25,代码来源:ApiExplorerServiceTests.cs

示例9: TryAddRoute

        public bool TryAddRoute(string routeName, string routeTemplate, IEnumerable<HttpMethod> methods, HttpRouteCollection routes, out IHttpRoute route)
        {
            route = null;

            try
            {
                var routeBuilder = CreateRouteBuilder(routeTemplate);
                var constraints = routeBuilder.Constraints;
                if (methods != null)
                {
                    // if the methods collection is not null, apply the constraint
                    // if the methods collection is empty, we'll create a constraint
                    // that disallows ALL methods
                    constraints.Add("httpMethod", new HttpMethodConstraint(methods.ToArray()));
                }
                route = routes.CreateRoute(routeBuilder.Template, routeBuilder.Defaults, constraints);
                routes.Add(routeName, route);
            }
            catch (Exception ex) when (!ex.IsFatal()) 
            {
                // catch any route parsing errors
                return false;
            }

            return true;
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:26,代码来源:HttpRouteFactory.cs

示例10: RegisterRoutes

        public static void RegisterRoutes(HttpRouteCollection routes)
        {
            // See http://github.com/mccalltd/AttributeRouting/wiki for more options.
            // To debug routes locally using the built in ASP.NET development server, go to /routes.axd

            routes.MapHttpAttributeRoutes();
        }
开发者ID:jalvarezz,项目名称:CarRental,代码行数:7,代码来源:AttributeRoutingHttpConfig.cs

示例11: Configure

 private static void Configure(HttpRouteCollection routes)
 {
     routes.MapHttpRoute(
             "DefaultApiWithId", 
             "Api/{controller}/{id}", 
             new { id = RouteParameter.Optional }, 
             new { id = @"\d+" });
 }
开发者ID:Zero1991,项目名称:Topshelf.Integrations,代码行数:8,代码来源:Program.cs

示例12: RegisterRoutes

        public static void RegisterRoutes(HttpRouteCollection routes)
        {
            // See http://github.com/mccalltd/AttributeRouting/wiki for more options.
            // To debug routes locally using the built in ASP.NET development server, go to /routes.axd

            Assembly assembly = Assembly.GetAssembly(typeof(IPDetectServer.Services.ServiceAssemble));
            routes.MapHttpAttributeRoutes(config=>config.AddRoutesFromAssembly(assembly));
        }
开发者ID:Jackie2014,项目名称:W1-IPS,代码行数:8,代码来源:AttributeRoutingHttp.cs

示例13: RegisterRoutes

 public static void RegisterRoutes(HttpRouteCollection routes)
 {
     routes.MapHttpRoute(
         name: "Leases",
         routeTemplate: "leases/{resource}/{leaseId}",
         defaults: new { controller = "Leases", resource = RouteParameter.Optional, leaseId = RouteParameter.Optional }
         );
 }
开发者ID:yvesgoeleven,项目名称:CodeDAzure.ServiceFabric,代码行数:8,代码来源:RouteConfig.cs

示例14: ConfigureWebApiRoutes

 private static void ConfigureWebApiRoutes(HttpRouteCollection routes)
 {
     routes.MapHttpRoute(
         "API Default",
         "api/{controller}/{id}",
         new { id = RouteParameter.Optional }
     );
 }
开发者ID:MatthewLymer,项目名称:TodoApp,代码行数:8,代码来源:Global.asax.cs

示例15: RegisterRoutes

 public static void RegisterRoutes(HttpRouteCollection routes)
 {
     routes.MapHttpRoute(
        "DefaultHttpRoute",
        "api/{controller}/{key}",
        defaults: new { key = RouteParameter.Optional },
        constraints: new { key = new GuidRouteConstraint() });
 }
开发者ID:dotnext24,项目名称:PingYourPackage,代码行数:8,代码来源:RouteConfig.cs


注:本文中的HttpRouteCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。