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


C# HttpRouteCollection.GetRouteData方法代码示例

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


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

示例1: TryAddRoute_MethodsCollectionNull_DoesNotApplyHttpMethodConstraint

        public static void TryAddRoute_MethodsCollectionNull_DoesNotApplyHttpMethodConstraint()
        {
            HttpRouteFactory routeFactory = new HttpRouteFactory("api");

            HttpRouteCollection routes = new HttpRouteCollection();
            IHttpRoute route = null;
            Assert.True(routeFactory.TryAddRoute("route1", "products/{category}/{id?}", null, routes, out route));

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/products/electronics/123");
            var routeData = routes.GetRouteData(request);
            Assert.Same(route, routeData.Route);

            request = new HttpRequestMessage(HttpMethod.Post, "http://host/api/products/electronics/123");
            routeData = routes.GetRouteData(request);
            Assert.Same(route, routeData.Route);
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:16,代码来源:HttpRouteFactoryTests.cs

示例2: TryAddRoute_AppliesHttpMethodConstraint

        public static void TryAddRoute_AppliesHttpMethodConstraint()
        {
            HttpRouteFactory routeFactory = new HttpRouteFactory("api");

            HttpRouteCollection routes = new HttpRouteCollection();
            IHttpRoute route1, route2;
            Assert.True(routeFactory.TryAddRoute("route1", "products/{category}/{id?}", new HttpMethod[] { HttpMethod.Get }, routes, out route1));
            Assert.True(routeFactory.TryAddRoute("route2", "products/{category}/{id}", new HttpMethod[] { HttpMethod.Post }, routes, out route2));

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/products/electronics/123");
            var routeData = routes.GetRouteData(request);
            Assert.Same(route1, routeData.Route);

            request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/products/electronics");
            routeData = routes.GetRouteData(request);
            Assert.Same(route1, routeData.Route);

            request = new HttpRequestMessage(HttpMethod.Post, "http://host/api/products/electronics/123");
            routeData = routes.GetRouteData(request);
            Assert.Same(route2, routeData.Route);
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:21,代码来源:HttpRouteFactoryTests.cs

示例3: TryAddRoute_AmbiguousRoute_FirstRouteIsChosen

        public static void TryAddRoute_AmbiguousRoute_FirstRouteIsChosen()
        {
            HttpRouteFactory routeFactory = new HttpRouteFactory("api");

            HttpRouteCollection routes = new HttpRouteCollection();
            IHttpRoute route1, route2;
            Assert.True(routeFactory.TryAddRoute("route1", "foo/bar/baz", null, routes, out route1));
            Assert.True(routeFactory.TryAddRoute("route2", "foo/bar/baz", null, routes, out route2));

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/api/foo/bar/baz");
            var routeData = routes.GetRouteData(request);
            Assert.Same(route1, routeData.Route);
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:13,代码来源:HttpRouteFactoryTests.cs

示例4: SetupBigRouteTable

        public void SetupBigRouteTable()
        {
            var route = new TreeRoute("");
            route.AddWithPath("x/foo/{controller}/{id}", r => { });
            route.AddWithPath("x/bar/{controller}/{id}", r => { });
            route.AddWithPath("x/baz/{controller}/{id}", r => { });
            route.AddWithPath("y/blip/{controller}/{id}", r => { });
            route.AddWithPath("y/flid/{controller}/{id}", r => { });
            route.AddWithPath("y/flod/{controller}/{id}", r => { });

            var routes = new HttpRouteCollection();
            routes.MapHttpRoute("a", "x/foo/{controller}/{id}");
            routes.MapHttpRoute("b", "x/bar/{controller}/{id}");
            routes.MapHttpRoute("c", "x/baz/{controller}/{id}");
            routes.MapHttpRoute("d", "y/blip/{controller}/{id}");
            routes.MapHttpRoute("e", "y/flid/{controller}/{id}");
            routes.MapHttpRoute("f", "y/flod/{controller}/{id}");

            var httpRequestMessage = new HttpRequestMessage() { RequestUri = new Uri("http://localhost/y/flid/boo/22") };

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            for (int i = 0; i < 1000000; i++)
            {
                var getRouteData = route.GetRouteData("/", httpRequestMessage);
            }

            stopwatch.Stop();
            Debug.WriteLine("That took " + stopwatch.ElapsedMilliseconds);

            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < 1000000; i++)
            {
                var mvcroute = routes.GetRouteData(httpRequestMessage);
            }
            stopwatch.Stop();
            Debug.WriteLine("That took " + stopwatch.ElapsedMilliseconds);
        }
开发者ID:darrelmiller,项目名称:ApiRouter,代码行数:41,代码来源:RouteTests.cs


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