本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}