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"); }
public void Register(RouteCollection routes) { routes.AddIE6Support(); routes.Map<HomeController.HomeUrl>(u => ""); routes.Map<PharmaceuticalController.PharmaceuticalAddUrl>(u => "pharma/"); }
public static void RegisterRoutes(RouteCollection routes) { var route = routes.MapRoute("foo-route", "foo/{id}", new { controller = "Test", action = "Index", id = UrlParameter.Optional }); route.DataTokens = new RouteValueDictionary(new { routeName = "foo-route" }); routes.Map("bar-route", "bar/{id}", new { controller = "Test", action = "Index", id = (string)null }); routes.Map("token-route", "tokens/{id}", new { dataToken = "BlahBlahBlah" }); routes.MapRoute("extension", "ext/{id}.mvc", new { controller = "Home", action = "Index", id = (string)null }); routes.MapRoute("mvc-default", "{controller}/{action}/{id}" , new { controller = "Test", action = "Index", id = (string)null }); routes.MapRoute("namespaces", "whatever{foo}", null, null, new[] { "MvcApplication1.Areas", "MvcApplication1.Areas.Area1" }); }
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); }
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()); }
private void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.Map("home", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = "" }); }
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); }
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)); }
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); }
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")); }
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); }
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" }); }
public void MapRouteWithExtraParameters() { var routes = new RouteCollection(); routes.Map("Patients/{mrn}/Labs/{id}", new { controller = "Labs", action = "Show" }); AssertRoute(routes, "~/Patients/123/Labs/abc", "GET", new { controller = "Labs", action = "Show", mrn = "123", id = "abc" }); }
public void MapRouteWithImplicitAction() { var routes = new RouteCollection(); routes.Map("{controller}", new { action = "Index" }); AssertRoute(routes, "~/Patients", "GET", new { controller = "Patients", action = "Index" }); }
public void MapRouteWithExplicitControllerAndAction() { var routes = new RouteCollection(); routes.Map("{controller}/{action}"); AssertRoute(routes, "~/Patients/Index", "GET", new { controller = "Patients", action = "Index" }); }
public static void Map(this RouteCollection routes, string url) { routes.Map(url, new { }); }
public void GetVirtualPathWithApplicationRootReturnsVirtualPath() { // Arrange var childRoutes = new RouteCollection(); childRoutes.Map("r1", "no-match", new Mock<IRouteHandler>().Object); childRoutes.Map("r2", "uno/{seg}/{seg2}", new Mock<IRouteHandler>().Object); var virtualPathResolver = new Mock<IVirtualPathResolver>(); virtualPathResolver.Setup(r => r.ToAbsolute("~/")).Returns("/"); var groupRoute = new GroupRoute(childRoutes, virtualPathResolver.Object); var httpContext = new Mock<HttpContextBase>(); httpContext.Setup(c => c.Request.Path).Returns("/qux"); httpContext.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/qux"); httpContext.Setup(c => c.Request.ApplicationPath).Returns("/Foo/Bar"); httpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s.Remove(0, "/Foo/Bar".Length)); var requestContext = new RequestContext(httpContext.Object, new RouteData()); // Act var routeValues = new RouteValueDictionary { { "seg", "dos" }, { "seg2", "three" } }.SetRouteName("r2"); var virtualPath = groupRoute.GetVirtualPath(requestContext, routeValues); // Assert PAssert.IsTrue(() => virtualPath != null); PAssert.IsTrue(() => virtualPath.VirtualPath == "uno/dos/three"); }
public void Register(RouteCollection routes) { routes.Map<HomeUrl>(u => ""); routes.Map<ContactUrl>(u => "Contact"); routes.Map<DiaryUrl>(u => "diary"); routes.Map<TodayUrl>(u => "today"); routes.Map<ThanksUrl>(u => "thanks"); routes.Map<AboutUrl>(u => "about"); routes.Map<BandLookingForAGigUrl>(u => "bandlookingforagig"); routes.Map<StolenGearListUrl>(u => "stolengear"); routes.Map<StolenGearUrl>(u => "stolengear/" + u.Id); routes.Map<VenuesUrl>(u => "Venues/"); routes.Map<VenuesMapUrl>(u => "Venues/Map"); routes.Map<VenueUrl>(u => "Venues/" + u.Venue); routes.Map<VenueMapUrl>(u => "Venues/" + u.Venue + "/Map"); routes.Map<GigUrl>(u => "Venues/" + u.Venue + "/" +u.Date + "/" + u.Month + "/" + u.Year); routes.Map<VenueUrl>(u => "Venues/" + u.Venue.CatchAll()); routes.Map<BandsUrl>(u => "bands"); routes.Map<BandUrl>(u => "bands/" + u.BandName); routes.Map<ClaimBandUrl>(u => "bands/" + u.BandName + "/claim"); routes.Map<ClaimThanksUrl>(u => "bands/" + u.BandName + "/thanks"); routes.Map<YearUrl>(u => u.Year.ToString()); routes.Map<MonthUrl>(u => u.Month + "/" + u.Year); routes.Map<DayUrl>(u => u.Date + "/" + u.Month + "/" + u.Year); routes.Map<DayMapUrl>(u => u.Date + "/" + u.Month + "/" + u.Year + "/map"); // catchalls routes.Map<ErrorUrl>(u => u.ContentPath.CatchAll()); }
public static void Map(this RouteCollection routes, string url, object defaults) { routes.Map(url, defaults, new { }); }
/// <summary> /// Maps all routes on TController annotated with a ResourceActionAttribute. /// OPTIONS and HEAD methods for each URI will be routed to a method on /// RestfulController that knows how to respond appropriately. /// For each URI provided, unsupported methods will be routed to a RestfulController /// method that returns a 405 status code. /// </summary> public static void Map <TController>(this RouteCollection routes) where TController : Controller { routes.Map <TController>(new MvcRouteHandler()); }
public void MapRouteWithHttpVerbAsString_DoesntMatchWrongVerb() { var routes = new RouteCollection(); routes.Map("{controller}/{action}", new { }, "GET"); Assert.IsNull(GetRoute(routes, "~/Patients/Index", "POST")); }
// The Map methods map to the MvcRouteHandler public static Route Map(this RouteCollection routes, string name, string url) { return(routes.Map(name, url, null, null, null)); }
public static void Map(this RouteCollection routes, string url, object defaults, string httpVerb) { routes.Map(url, defaults, new { httpMethod = new HttpMethodConstraint(httpVerb) }); }
public void Register(RouteCollection routes) { routes.Map<HomeUrl>(u => ""); }
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")); }
public void MapRouteWithHttpVerbAsString() { var routes = new RouteCollection(); routes.Map("{controller}/{action}", new { }, "GET"); AssertRoute(routes, "~/Patients/Index", "GET", new { controller = "Patients", action = "Index" }); }
public static void Map(this RouteCollection routes, string url, object defaults, object constraints) { routes.Map(null, url, defaults, constraints); }
public void Register(RouteCollection routes) { routes.Map<HomeUrl>(u => ""); routes.Map<AddUrl>(u => "Add"); routes.Map<AddRepeatingGigUrl>(u => "RepeatingGig/Add"); routes.Map<RepeatingGigUrl>(u => "RepeatingGig/" + u.Id); routes.Map<RepeatingGigsUrl>(u => "RepeatingGigs"); routes.Map<AdminPanelUrl>(u => "adminpanel"); routes.Map<AddCreatedDatesUrl>(u => "adminpanel/addcreateddates"); routes.Map<DataCleanseSpacesUrl>(u => "adminpanel/datacleanse/spaces"); routes.Map<LookupUrl>(u => "Lookup/" + u.Which); routes.Map<ExportUrl>(u => "export"); routes.Map<ListUrl>(u => "list"); routes.Map<EditUrl>(u => "gig/" + u.RecordId); routes.Map<CheckDateUrl>(u => "checkdate"); routes.Map<VenuesUrl>(u => "venues"); routes.Map<EditVenueUrl>(u => "venues/" + u.VenueName); routes.Map<VenueMainImageUrl>(u => "venues/" + u.VenueName + "/mainimage"); routes.Map<MetadataUrl>(u => "metadata/" + u.Id); routes.Map<BandsUrl>(u => "bands"); routes.Map<BandUrl>(u => "bands/" + u.BandName); routes.Map<StolenGearListUrl>(u => "stolengearlist"); routes.Map<AddStolenGearUrl>(u => "stolengear"); routes.Map<StolenGearUrl>(u => "stolengear/" + u.Id); }
public void RewriteWithRoutingParameters() { 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"), true, "/"); mockContext.AssertWasCalled(context => context.RewritePath("Patients/Show?id=123")); }
public static Route Map(this RouteCollection routes, string name, string url, object defaults, object constraints) { return(routes.Map(name, url, defaults, constraints, null)); }
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]); }