本文整理汇总了C#中RouteCollection.Map方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.Map方法的具体用法?C# RouteCollection.Map怎么用?C# RouteCollection.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.Map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Redirect From Old Route to New route
var targetRoute = routes.Map("target", "yo/{id}/{action}", new { controller = "Home" });
routes.Redirect(r => r.MapRoute("legacy", "foo/{id}/baz/{action}")).To(targetRoute, new { id = "123", action = "index" });
routes.Redirect(r => r.MapRoute("legacy2", "foo/baz")).To(targetRoute, new { id = "123", action = "index" });
// Map Delegate
routes.MapDelegate("map-delegate", "this-is-a-test", rc => rc.HttpContext.Response.Write("Yeah, it's a test"));
routes.MapDelegate("map-delegate-incoming-only", "this-is-a-test", new { whatever = new IncomingOnlyRouteConstraint() }, rc => rc.HttpContext.Response.Write("Yeah, it's a test"));
// Map HTTP Handlers
routes.MapHttpHandler<HelloWorldHttpHandler>("hello-world", "handlers/helloworld");
routes.MapHttpHandler("hello-world2", "handlers/helloworld2", new HelloWorldHttpHandler());
RouteCollection someRoutes = new RouteCollection();
someRoutes.MapHttpHandler<HelloWorldHttpHandler>("hello-world3", "handlers/helloworld3");
someRoutes.MapHttpHandler("hello-world4", "handlers/helloworld4", new HelloWorldHttpHandler());
var groupRoute = new GroupRoute("~/section", someRoutes);
routes.Add("group", groupRoute);
var mvcRoutes = new RouteCollection();
mvcRoutes.Map("foo1", "foo/{controller}", new { action = "index" });
mvcRoutes.Map("foo2", "foo2/{controller}", new { action = "index" });
routes.Add("group2", new GroupRoute("~/group2sec", mvcRoutes));
var defaultRoute = routes.Map(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
).SetRouteName("Default");
}
示例2: Register
public void Register(RouteCollection routes)
{
routes.AddIE6Support();
routes.Map<HomeController.HomeUrl>(u => "");
routes.Map<PharmaceuticalController.PharmaceuticalAddUrl>(u => "pharma/");
}
示例3: RegisterRoutes
protected override void RegisterRoutes(RouteCollection routes)
{
var imgns = new[] { "MvcSolution.Web.Controllers.*" };
routes.Map("img/{size}/default-{name}.{format}", "image", "SystemDefault", imgns);
routes.Map("img/{size}/t{imageType}t{yearMonth}-{id}.{format}", "image", "index", imgns);
routes.Map("img/{size}/{parameter}", "image", "index", imgns);
var ns = new[] { "MvcSolution.Web.Public.Controllers.*" };
var defaults = new { controller = "Home", action = "Index", id = UrlParameter.Optional };
routes.Map("", defaults, ns);
routes.Map("{controler}/{action}/{id}", defaults, ns);
}
示例4: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Snooze provides some handy features...
routes.AddVersionedStaticFilesSupport();
routes.AddIE6Support();
routes.Map<HomeUrl>(h => "");
routes.Map<BooksUrl>(b => "books");
routes.Map<BookUrl>(b => "book/" + b.BookId);
routes.Map<BookCommentsUrl>(c => "comments");
routes.Map<BookCommentUrl>(c => c.CommentId.ToString());
}
示例5: RegisterRoutes
protected override void RegisterRoutes(RouteCollection routes)
{
var defaults = new { controller = "home", action = "index", id = UrlParameter.Optional };
var ns = new[] { "MvcSolution.Web.Public.Controllers.*" };
routes.Map("{controller}/{action}/{id}", defaults, ns);
}
示例6: RegisterRoutes
private void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Map("home",
"{controller}/{action}/{id}",
new { controller = "home", action = "index", id = "" });
}
示例7: MapShouldAddAllResourcefulRoutes
public void MapShouldAddAllResourcefulRoutes()
{
var routes = new RouteCollection();
routes.Map<FirstController>();
Assert.That("GET /First", Routes.To(new {controller = "First", action = "First"}, routes));
Assert.That("POST /First", Routes.To(new {controller = "First", action = "MethodNotSupported"}, routes));
Assert.That("HEAD /First", Routes.To(new {controller = "First", action = "Head"}, routes));
Assert.That("OPTIONS /First", Routes.To(new {controller = "First", action = "Options"}, routes));
}
示例8: SimpleRewrite
public void SimpleRewrite()
{
var routes = new RouteCollection();
routes.Map("Patients", new { controller = "Patients", action = "Index" });
var tokenizer = new RoutingBasedUrlTokenizer(routes);
var mockContext = TestFactory.CreateMockContext("~/Patients");
tokenizer.Context = mockContext;
tokenizer.TokenizeUrl("/Patients/", new Uri("http://localhost/Patients/"), true, "/");
mockContext.AssertWasCalled(context => context.RewritePath("Patients/Index"));
}
示例9: ReturnsMatchingRouteValues
public void ReturnsMatchingRouteValues()
{
var routes = new RouteCollection();
routes.Map("Patients/{id}", new { controller = "Patients", action = "Show" });
var tokenizer = new RoutingBasedUrlTokenizer(routes);
tokenizer.Context = TestFactory.CreateMockContext("~/Patients/123");
var urlInfo = tokenizer.TokenizeUrl("/Patients/123", new Uri("http://localhost/Patients/123"), true, "/");
Assert.AreEqual("Patients", urlInfo.Controller);
Assert.AreEqual("Show", urlInfo.Action);
}
示例10: Register
public void Register(RouteCollection routes)
{
routes.Map<HomeUrl>(h => "");
routes.Map<BooksUrl>(b => "books");
routes.Map<BookUrl>(b => "book/" + b.BookId);
routes.Map<BookCommentsUrl>(c => "comments");
routes.Map<BookCommentUrl>(c => c.CommentId.ToString());
routes.Map<PartialItemUrl>(c => "partial/item/" + c.Something);
}
示例11: RewriteWithRoutingParametersAndQuerystring
public void RewriteWithRoutingParametersAndQuerystring()
{
var routes = new RouteCollection();
routes.Map("Patients/{id}", new { controller = "Patients", action = "Show" });
var tokenizer = new RoutingBasedUrlTokenizer(routes);
var mockContext = TestFactory.CreateMockContext("~/Patients/123");
tokenizer.Context = mockContext;
tokenizer.TokenizeUrl("/Patients/123", new Uri("http://localhost/Patients/123?debug=true"), true, "/");
Assert.AreEqual("Patients/Show?debug=true&id=123",
mockContext.GetArgumentsForCallsMadeOn(context => context.RewritePath(null))[0][0]);
}
示例12: MapRouteWithHttpVerbAsString_DoesntMatchWrongVerb
public void MapRouteWithHttpVerbAsString_DoesntMatchWrongVerb()
{
var routes = new RouteCollection();
routes.Map("{controller}/{action}", new { }, "GET");
Assert.IsNull(GetRoute(routes, "~/Patients/Index", "POST"));
}
示例13: MapRouteWithHttpVerbAsString
public void MapRouteWithHttpVerbAsString()
{
var routes = new RouteCollection();
routes.Map("{controller}/{action}", new { }, "GET");
AssertRoute(routes, "~/Patients/Index", "GET",
new { controller = "Patients", action = "Index" });
}
示例14: MapRouteWithExplicitHttpVerb_DoesntMatchWrongVerb
public void MapRouteWithExplicitHttpVerb_DoesntMatchWrongVerb()
{
var routes = new RouteCollection();
routes.Map("{controller}/{action}", new { }, new { httpMethod = new HttpMethodConstraint("GET") });
Assert.IsNull(GetRoute(routes, "~/Patients/Index", "POST"));
}
示例15: MapRouteWithHttpVerb
public void MapRouteWithHttpVerb()
{
var routes = new RouteCollection();
routes.Map("{controller}/{action}", new { }, new { httpMethod = new HttpMethodConstraint("GET") });
AssertRoute(routes, "~/Patients/Index", "GET",
new { controller = "Patients", action = "Index" });
}