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


C# RouteCollection.Map方法代码示例

本文整理汇总了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");
        }
开发者ID:intertrendSoftware,项目名称:RouteMagic-ITFork,代码行数:33,代码来源:Global.asax.cs

示例2: Register

        public void Register(RouteCollection routes)
        {
            routes.AddIE6Support();

            routes.Map<HomeController.HomeUrl>(u => "");
            routes.Map<PharmaceuticalController.PharmaceuticalAddUrl>(u => "pharma/");
        }
开发者ID:rhmg,项目名称:ukps-spike,代码行数:7,代码来源:RouteRegistration.cs

示例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);
        }
开发者ID:yuandong618,项目名称:mvcsolution,代码行数:13,代码来源:Global.asax.cs

示例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());
        }
开发者ID:ryansroberts,项目名称:Snooze,代码行数:14,代码来源:Global.asax.cs

示例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);

        }
开发者ID:dut3062796s,项目名称:mvcsolution,代码行数:8,代码来源:Global.asax.cs

示例6: RegisterRoutes

        private void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.Map("home",
                       "{controller}/{action}/{id}",
                       new { controller = "home", action = "index", id = "" });
        }
开发者ID:tacoman667,项目名称:pseudo_mvc,代码行数:8,代码来源:Global.asax.cs

示例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));
        }
开发者ID:Raffaferreira,项目名称:RestMvc,代码行数:10,代码来源:RouteCollectionExtensionsTest.cs

示例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"));
        }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:12,代码来源:RoutingBasedUrlTokenizerTest.cs

示例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);
        }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:12,代码来源:RoutingBasedUrlTokenizerTest.cs

示例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);
 }
开发者ID:ryansroberts,项目名称:Snooze,代码行数:9,代码来源:Global.asax.cs

示例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]);
        }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:13,代码来源:RoutingBasedUrlTokenizerTest.cs

示例12: MapRouteWithHttpVerbAsString_DoesntMatchWrongVerb

 public void MapRouteWithHttpVerbAsString_DoesntMatchWrongVerb()
 {
     var routes = new RouteCollection();
     routes.Map("{controller}/{action}", new { }, "GET");
     Assert.IsNull(GetRoute(routes, "~/Patients/Index", "POST"));
 }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:6,代码来源:RouteCollectionExtensionsTest.cs

示例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" });
 }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:7,代码来源:RouteCollectionExtensionsTest.cs

示例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"));
 }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:6,代码来源:RouteCollectionExtensionsTest.cs

示例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" });
 }
开发者ID:bbyars,项目名称:Castle.MonoRail.Routing,代码行数:7,代码来源:RouteCollectionExtensionsTest.cs


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