C# (CSharp) RouteCollection Code Examples

C# (CSharp) RouteCollection - 30 примеров найдено. Это лучшие примеры C# (CSharp) кода для RouteCollection, полученные из open source проектов. Вы можете ставить оценку каждому примеру, чтобы помочь нам улучшить качество примеров.
 /// <summary>
 /// Registers all api controller routes
 /// </summary>
 /// <param name="routes"></param>
 /// <param name="apiControllers"></param>
 private void MapRouteApiControllers(RouteCollection routes, IEnumerable<PluginControllerMetadata> apiControllers)
 {
     foreach (var s in apiControllers)
     {
         this.RouteControllerPlugin(s.ControllerName, s.ControllerType, routes, "", "", UrlParameter.Optional, "api", isMvc: false);
     }
 }
Пример #2
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapRoute(
            //    name: "Create",
            //    url: "Tool/Create",
            //    defaults: new { controller = "Tool", action = "Create" }
            //);

            // This route creates a short URL to a specific tool.
            // this makes it easy to copy and paste.
            // For example, http://localhost/Tool/5
            routes.MapRoute(
                name: "Launch",
                url: "Tool/{id}", 
                defaults: new { controller = "Tool", action = "View" },
                constraints: new { id = @"\d+" }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
Пример #3
0
        public void Init() {
            _settingsA = new ShellSettings { Name = "Alpha" };
            _settingsB = new ShellSettings { Name = "Beta", };
            _routes = new RouteCollection();

            var rootBuilder = new ContainerBuilder();
            rootBuilder.Register(ctx => _routes);
            rootBuilder.RegisterType<ShellRoute>().InstancePerDependency();
            rootBuilder.RegisterType<RunningShellTable>().As<IRunningShellTable>().SingleInstance();
            rootBuilder.RegisterModule(new WorkContextModule());
            rootBuilder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>().InstancePerMatchingLifetimeScope("shell");
            rootBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>();
            rootBuilder.RegisterType<ExtensionManager>().As<IExtensionManager>();
            rootBuilder.RegisterType<StubCacheManager>().As<ICacheManager>();
            rootBuilder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
            rootBuilder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();

            _rootContainer = rootBuilder.Build();

            _containerA = _rootContainer.BeginLifetimeScope(
                "shell",
                builder => {
                    builder.Register(ctx => _settingsA);
                    builder.RegisterType<RoutePublisher>().As<IRoutePublisher>().InstancePerMatchingLifetimeScope("shell");
                });

            _containerB = _rootContainer.BeginLifetimeScope(
                "shell",
                builder => {
                    builder.Register(ctx => _settingsB);
                    builder.RegisterType<RoutePublisher>().As<IRoutePublisher>().InstancePerMatchingLifetimeScope("shell");
                });
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // This controller-per-type route is ideal for GetAll calls.
            // It finds the method on the controller using WebAPI conventions
            // The template has no parameters.
            routes.MapHttpRoute(
                name: ControllerOnly,
                routeTemplate: "api/{controller}"
            );

            routes.MapHttpRoute(
                name: ControllerAndId,
                routeTemplate: "api/{controller}/{id}",
                defaults: null, //defaults: new { id = RouteParameter.Optional } //,
                constraints: new { id = @"^\d+$" } // id must be all digits
            );

            // ex: api/lookups/all
            // ex: api/lookups/rooms
            routes.MapHttpRoute(
                name: ControllerAction,
                routeTemplate: "api/{controller}/{action}"
            );

            //PAPA: Commented this out because we wont be using MVC views
            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            //);
        }
Пример #5
0
        public void Register(RouteCollection routes)
        {
            // add catch-all routes for incoming routes that will match dynamically created controllers
            for (var n = 0; n < 3 /*ContentTreeRouteRegistrator.MaxDepthForContentTreeUrlSegments*/; n++)
            {
                var sb = new StringBuilder();
                for (var x = 0; x <= n; x++)
                {
                    sb.Append(string.Format("{{nodesegment-{0}}}/", x));
                }
                AddRoute(routes, string.Format("{0}{{action}}", sb));
            }

            // add hard coded routes for all instances of this engine type
            foreach (var treeNode in treeNodeRepository.GetAll().Where(a => a.Type == this.GetType().AssemblyQualifiedName))
            {
                var url = treeNodeIdToUrl.GetUrlByTreeNodeId(treeNode.Id);
                if (url.StartsWith("/")) url = url.Substring(1);
                url = url + "/{action}";

                var controllerName = (this.GetType().Name ?? string.Empty).Replace("Controller", string.Empty);

                routes.MapRoute(
                    null,
                    url,
                    new { controller = controllerName, action = "Index" }
                );
            }
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Plugins", "plugins/{action}", new { controller = "Plugins" });
            routes.MapRoute("BackboneDirectAccess", "{*url}", new { controller = "Home", action = "Index" });
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "ApiSearch",                                           // Route name
                "artist/search/{search_criteria}/{page_number}/{page_size}",                            // URL with parameters
                new { controller = "Api", action = "Search", page_number = UrlParameter.Optional, page_size = UrlParameter.Optional }  // Parameter defaults
            );

               // /artist/6c44e9c22-ef82-4a77-9bcd-af6c958446d6/albums
            routes.MapRoute(
                "GetTopAlbums",                                           // Route name
                "artist/{artist_id}/albums",                            // URL with parameters
                new { controller = "Api", action = "GetTopAlbums" }  // Parameter defaults
            );

            // /artist/6c44e9c22-ef82-4a77-9bcd-af6c958446d6/albums
            routes.MapRoute(
                "GetReleases",                                           // Route name
                "artist/{artist_id}/releases",                            // URL with parameters
                new { controller = "Api", action = "GetReleases" }  // Parameter defaults
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
Пример #8
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Match empty URL (~/)
            routes.MapRoute(
                null,
                string.Empty,
                new
                {
                    controller = "Bookmarks",
                    action = "List",
                    page = 1
                }
            );

            // Match new
            routes.MapRoute(
               null,
               "New",
               new
               {
                   controller = "Bookmarks",
                   action = "New",
                   page = 1
               }
               );

            // Map numeric pages ~/Page123, ~/Page2
            routes.MapRoute(
                null,
                "Page{page}",
                new
                {
                    controller = "Bookmarks",
                    action = "List"
                },
                new
                {
                    page = @"\d+"
                }
            );

            // Match Admin
            routes.MapRoute(
                null,
                "Bookmarks/{controller}/{action}",
                new
                {
                    controller = "Bookmarks",
                    action = "List",
                    page = 1
                }
            );

            routes.MapRoute(
               null,
               "{controller}/{action}"
               );
        }
Пример #9
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            AreaRegistration.RegisterAllAreas();

            routes.MapRoute(
                name: "Board",
                url: "",
                defaults: new { controller = "Home", action = "Board" }
            );

            routes.MapRoute(
                name: "Vote",
                url: "vote",
                defaults: new { controller = "Home", action = "Index" }
            );

            routes.MapRoute(
                name: "Login",
                url: "login",
                defaults: new { controller = "Account", action = "Login" }
            );

            routes.MapRoute(
                name: "Registration",
                url: "registration",
                defaults: new { controller = "Account", action = "Register" }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}",
                defaults: new { controller = "Home", action = "Index" }
            );
        }
        public void Setup()
        {
            RouteAssert.UseAssertEngine(new NunitAssertEngine());

            routes = new RouteCollection();
            routes.MapAttributeRoutesInAssembly(typeof(HomeAttrController));
        }
Пример #11
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
              name: "ListTopRoute",
              url: "ListTop/{page}",
              defaults: new { controller = "Page", action = "ListTopPages", page = UrlParameter.Optional }
          );

            routes.MapRoute(
              name: "ListRoute",
              url: "List/{category}/{idCategory}/{page}",
              defaults: new { controller = "Page", action = "List", category = UrlParameter.Optional, idCategory = UrlParameter.Optional, page = UrlParameter.Optional }
          );

            routes.MapRoute(
              name: "ArchiveRoute",
              url: "Archive/{page}/{id}",
              defaults: new { controller = "Page", action = "Index", page = UrlParameter.Optional, id = UrlParameter.Optional }
          );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

          
        }
Пример #12
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Default", "", new { controller = "LogViewer", action = "Index", id = UrlParameter.Optional }
            );
        }
Пример #13
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapRoute(
            //    "Default", // Route name
            //    "{controller}/{action}", // URL with parameters
            //    new { controller = "Tasks", action = "Index"} // Parameter defaults
            //    );

            routes.MapRoute("About", "{controller}/{action}", new { controller = "Tasks", action = "About" });

            routes.MapRoute(
                "Tasks", "{controller}/{action}/{project}", new { controller = "Tasks", action = "TaskList" });

            routes.MapRoute(
                "ImageRoute",
                "{controller}/{action}/{id}",
                new { controller = "Tasks", action = "Images" });

            routes.MapRoute(
                "ClearServerCache", "{controller}/{action}", new { controller = "Tasks", action = "ClearServerCache" });

            routes.MapRoute(
                "ImportData",
                "{controller}/{action}/{project}",
                new { controller = "Tasks", action = "ImportData" });
        }
Пример #14
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            routes.MapRoute("cache.manifest", "cache.manifest", new { controller = "Resources", action = "Manifest" });

            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            routes.MapRoute(
                name: "Readability",
                url: "{controller}/{action}/{url}",
                defaults: new { controller = "Readability", action = "Index" }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
Пример #15
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "file_upload",
                url: "file/upload/{file}",
                defaults: new { controller = "Blog", action = "FileUpload", file = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "manage_blog",
                url: "manage/blog/{action}/{id}",
                defaults: new { controller = "Blog", action = "Index", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "manage_product",
                url: "manage/product/{action}/{id}",
                defaults: new { controller = "Product", action = "Index", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "manage",
                url: "manage/{action}/{id}",
                defaults: new { controller = "Management", action = "Index", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Home", id = UrlParameter.Optional }
            );
        }
Пример #16
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // This controller-per-type route is ideal for GetAll calls.
            // It finds the method on the controller using WebAPI conventions
            // The template has no parameters.
            //
            // ex: api/sessionbriefs
            // ex: api/sessions
            // ex: api/persons
            routes.MapHttpRoute(
                name: ControllerOnly,
                routeTemplate: "api/{controller}"
                );

            // This is the default route that a "File | New MVC 4 " project creates.
            // (I changed the name, removed the defaults, and added the constraints)
            //
            // This controller-per-type route lets us fetch a single resource by numeric id
            // It finds the appropriate method GetById method
            // on the controller using WebAPI conventions
            // The {id} is not optional, must be an integer, and
            // must match a method with a parameter named "id" (case insensitive)
            //
            //  ex: api/sessions/1
            //  ex: api/persons/1
            routes.MapHttpRoute(
                name: ControllerAndId,
                routeTemplate: "api/{controller}/{id}",
                defaults: null, //defaults: new { id = RouteParameter.Optional } //,
                constraints: new {id = @"^\d+$"} // id must be all digits
                );

            /********************************************************
            * The integer id constraint is necessary to distinguish
            * the {id} route above from the {action} route below.
            * For example, the route above handles
            *     "api/sessions/1"
            * whereas the route below handles
            *     "api/lookups/all"
            ********************************************************/

            // This RPC style route is great for lookups and custom calls
            // It matches the {action} to a method on the controller
            //
            // ex: api/lookups/all
            // ex: api/lookups/rooms
            routes.MapHttpRoute(
                name: ControllerAction,
                routeTemplate: "api/{controller}/{action}"
                );

            //PAPA: Commented this out because we wont be using MVC views
            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            //);
        }
Пример #17
0
 public static void RegisterRoutes(RouteCollection routes)
 {
     routes.MapRoute(
         "Throw Exception",
         "ThrowException",
         new { controller = "ThrowException", action = "Index" });
 }
        public void Routes_should_be_same_which_is_passed_in_constructor()
        {
            var routes = new RouteCollection();
            var registration = new RegisterRoutesBaseTestDouble(routes);

            Assert.Same(routes, registration.PublicRoutes);
        }
Пример #19
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.MapMvcAttributeRoutes();

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // 1 - Home

            routes.MapRoute(null, "", new { controller = "Vitrine", action = "ListaProdutos", categoria = (string)null, pagina = 1 });

            // 2 -
            routes.MapRoute(null,
                "Pagina{pagina}",
                new { controller = "Vitrine", action = "ListaProdutos", categoria = (string)null }, new { pagina = @"\d+" });

            routes.MapRoute(null,
                "{categoria}", new { controller = "Vitrine", action = "ListaProdutos", pagina = 1 });

            routes.MapRoute(null,
                "{categoria}/Pagina{pagina}", new { controller = "Vitrine", action = "ListaProdutos" }, new { pagina = @"\d+" });

            //routes.MapRoute(
            //    "ObterImagem",
            //    "Vitrine/ObterImagem/{produtoId}",
            //    new {controller = "Vitrine", action = "ObterImagem", produtoId = UrlParameter.Optional});

            routes.MapRoute(null, "{controller}/{action}");
        }
 internal RequestInfo(RouteCollection applicationRoutes, string url, string httpMethod)
 {
     HttpContext = TestUtility.GetHttpContext(PrepareUrl(url), httpMethod);
     _applicationRoutes = applicationRoutes;
     //routeData = applicationRoutes.GetRouteData(httpContext);
     _requestUrl = url;
 }
Пример #21
0
        public void RegisterRoutes(RouteCollection routes)
        {

            routes.MapRoute("Apps.D3Map.index", "Apps/D3Map/Index",
                new { controller = "D3Map", action = "Index" },
                new[] { "R2.Halo.Apps.D3Map.Controllers" });
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            /*rutarea catre incarcarea de fisier*/
            routes.MapRoute(
                "Upload", // Route name
                "Up", // URL with parameters
                new { controller = "Load", action = "Upload" }
            );

            /*rutarea catre incarcarea unui document deja existent*/
            routes.MapRoute(
                "Load", // Route name
                "Load/{id}", // URL with parameters
                new { controller = "Load", action = "Load", id = UrlParameter.Optional}
            );

            /*rutarea catre controllerul principal*/
            routes.MapRoute(
                "Home", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

            /*rutarea catre controllerul de cereri XML*/
            routes.MapRoute(
                "Get", // Route name
                "{controller}/{action}/{id}/{question}", // URL with parameters
                new { controller = "Get", action = "Summary", id = UrlParameter.Optional, question = UrlParameter.Optional }
            );
        }
Пример #23
0
		private static void RegisterSpecialRoutes(RouteCollection routes)
		{
			// /Wiki/Special:{id} urls
			routes.MapRoute(
				"SpecialPages",
				"Wiki/Special:{id}",
				new { controller = "SpecialPages", action = "Index" }
			);

			// /Wiki/Help:About
			routes.MapRoute(
				"Help:About",
				"Wiki/Help:About",
				new { controller = "Help", action = "About" },
				null,
				new string[] { "Roadkill.Core.Mvc.Controllers" }
			);

			// /Wiki/Help:Cheatsheet
			routes.MapRoute(
				"Help:CheatSheet",
				"Wiki/Help:Cheatsheet",
				new { controller = "Help", action = "Index" },
				null,
				new string[] { "Roadkill.Core.Mvc.Controllers" }
			);
		}
Пример #24
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //Send to help area by default
            routes.MapRoute("Help Area", "", new { controller = "Help", action = "Index" } ).DataTokens = new RouteValueDictionary(new { area = "HelpPage" });
        }
Пример #25
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            // Kind of hackish but will do for now.
            // If this list grows, we might have to look at another solution.
            var lookup = new Dictionary<string, string>()
            {
                {"what-is-cake", "/docs/overview/features"},
                {"getting-started", "/docs/tutorials/getting-started"},
                {"documentation", "/docs"},
                {"documentation/tasks", "/docs/fundamentals/tasks"},
                {"documentation/dependencies", "/docs/fundamentals/dependencies"},
                {"documentation/criteria", "/docs/fundamentals/criteria"},
                {"documentation/error-handling", "/docs/fundamentals/error-handling"},
                {"documentation/error-reporting", "/docs/fundamentals/error-handling"},
                {"documentation/finally-block", "/docs/fundamentals/finally-block"},
                {"documentation/setup-and-teardown", "/docs/fundamentals/setup-and-teardown"},
                {"documentation/running-targets", "/docs/fundamentals/running-targets"},
                {"documentation/script-aliases", "/docs/fundamentals/aliases"},
                {"contribute", "/docs/contributing/guidelines"},
                {"contribute/contribution-guidelines", "/docs/contributing/guidelines"}
            };

            var index = 1;
            foreach (var pair in lookup)
            {
                routes.MapRoute(
                    $"Legacy{index}",
                    pair.Key,
                    new { controller = "Redirect", action = "Index", path = pair.Value});

                index++;
            }
        }
Пример #26
0
	/// <summary>
	/// Registers all surface controller routes
	/// </summary>
	/// <param name="routes"></param>
	/// <param name="surfaceControllers"></param>
	/// <remarks>
	/// The routes will be:
	/// 
	/// /Umbraco/[AreaName]/[ControllerName]/[Action]/[Id]
	/// </remarks>
	private void MapRouteSurfaceControllers(RouteCollection routes, IEnumerable<PluginControllerMetadata> surfaceControllers)
	{
		foreach (var s in surfaceControllers)
		{
			this.RouteControllerPlugin(s.ControllerName, s.ControllerType, routes, "Surface", "Index", UrlParameter.Optional, "surface");
		}
	}
Пример #27
0
 public static void RegisterRoutes(RouteCollection routes)
 {
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     routes.MapRoute(null,
     "",
     new
     {
         controller = "Product",
         action = "List",
         category = (string)null,
         page = 1
     }
     );
     routes.MapRoute(null,
     "Page{page}",
     new { controller = "Product", action = "List", category = (string)null },
     new { page = @"\d+" }
     );
     routes.MapRoute(null,
     "{category}",
     new { controller = "Product", action = "List", page = 1 }
     );
     routes.MapRoute(null,
     "{category}/Page{page}",
     new { controller = "Product", action = "List" },
     new { page = @"\d+" }
     );
     routes.MapRoute(null, "{controller}/{action}");
 }
Пример #28
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Poll",
                url: "{shortUrl}",
                defaults: new { controller = "Home", action = "Poll" }

                );

            routes.MapRoute(
                name: "PollResults",
                url: "PollResults/{shortUrl}",
                defaults: new { controller = "Home", action = "PollResults" }

                );

            routes.MapRoute(
                name: "AdminPoll",
                url: "AdminPoll/{password}",
                defaults: new { controller = "Home", action = "AdminPoll" }

                );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
Пример #29
0
 public static void RegisterRoutes(RouteCollection routes) {
     routes.MapHttpRoute(
         name: "DefaultApi",
         routeTemplate: "api/{controller}/{id}",
         defaults: new {id = RouteParameter.Optional}
         );
 }
Пример #30
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "request",
                url: "{site}/request/{id}",
                defaults: new { site = "none", controller = "Request", action = "Index", id = UrlParameter.Optional }
                );

            routes.MapRoute(
                name: "sitebase",
                url: "{site}/{controller}/{action}/{id}",
                defaults: new {site = "none", controller = "Home", action = "Index", id = UrlParameter.Optional}
                );

            //routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            //);
        }