本文整理汇总了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]);
}
示例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" });
}
示例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}" );
}
示例4: Configure
private void Configure(HttpRouteCollection routes)
{
routes.MapHttpRoute(
"DefaultApiWithId",
"Api/TestDependency",
new { controller = "TestDependency" });
}
示例5: RegisterRoutes
public static void RegisterRoutes(HttpRouteCollection routes)
{
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例11: Configure
private static void Configure(HttpRouteCollection routes)
{
routes.MapHttpRoute(
"DefaultApiWithId",
"Api/{controller}/{id}",
new { id = RouteParameter.Optional },
new { id = @"\d+" });
}
示例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));
}
示例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 }
);
}
示例14: ConfigureWebApiRoutes
private static void ConfigureWebApiRoutes(HttpRouteCollection routes)
{
routes.MapHttpRoute(
"API Default",
"api/{controller}/{id}",
new { id = RouteParameter.Optional }
);
}
示例15: RegisterRoutes
public static void RegisterRoutes(HttpRouteCollection routes)
{
routes.MapHttpRoute(
"DefaultHttpRoute",
"api/{controller}/{key}",
defaults: new { key = RouteParameter.Optional },
constraints: new { key = new GuidRouteConstraint() });
}