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


C# RouteCollection.MapHttpRoute方法代码示例

本文整理汇总了C#中RouteCollection.MapHttpRoute方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.MapHttpRoute方法的具体用法?C# RouteCollection.MapHttpRoute怎么用?C# RouteCollection.MapHttpRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RouteCollection的用法示例。


在下文中一共展示了RouteCollection.MapHttpRoute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterRoutes

        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 }
            //);
        }
开发者ID:petryxadubyk,项目名称:BaseRepository,代码行数:60,代码来源:RouteConfig.cs

示例2: RegisterRoutes

        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 }
            //);
        }
开发者ID:OleksandrKulchytskyi,项目名称:SAPAspNetMvc,代码行数:33,代码来源:RouteConfig.cs

示例3: RegisterRoutes

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

            routes.MapHttpRoute(
                name: "AnswersActionApi",
                routeTemplate: "api/questions/{questionId}/answers/{answerId}/{action}",
                defaults: new { controller = "Answers", answerId = RouteParameter.Optional, action = RouteParameter.Optional }
            );

            routes.MapHttpRoute(
                name: "AnswersApi",
                routeTemplate: "api/questions/{questionId}/answers/{answerId}",
                defaults: new { controller = "Answers", answerId = RouteParameter.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 }
            );
        }
开发者ID:andlju,项目名称:quickvoter,代码行数:28,代码来源:RouteConfig.cs

示例4: RegisterRoutes

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

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

            routes.MapHttpRoute(
                name: "numbersByContactID",
                routeTemplate: "api/contacts/{contactID}/contactNumbers",
                defaults: new { controller = "contactNumbers", action = "GetByContactID" },
                constraints: new
                    {
                        contactID = @"\d+",
                        httpMethod = new HttpMethodConstraint(new string[] { "Get" })
                    }
                );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
开发者ID:egzonzeneli,项目名称:ALNUG---Backbone-Demo,代码行数:27,代码来源:RouteConfig.cs

示例5: RegisterRoutes

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.LowercaseUrls = true;

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

            routes.MapHttpRoute(
                name: "ApiApplication",
                routeTemplate: "api/v1/acc/{acc}/app/{app}",
                defaults: new {controller = "Application"}
                );

            routes.MapHttpRoute(
                name: "ApiLog",
                routeTemplate: "api/v1/acc/{acc}/app/{app}/logs/{id}",
                defaults: new {controller = "Log", id = UrlParameter.Optional}
                );

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

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
                );
        }
开发者ID:sidlovskyy,项目名称:quickstart-mvc,代码行数:30,代码来源:RouteConfig.cs

示例6: RegisterRoutes

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

            routes.MapHttpRoute(
                name: "SurveysApi",
                routeTemplate: "api/surveys/{id}",
                defaults: new { Controller = "Survey", id = RouteParameter.Optional });

            routes.MapHttpRoute(
                name: "SubmissionsApi",
                routeTemplate: "api/surveys/{surveyId}/submissions/{submissionId}",
                defaults: new { Controller = "SurveySubmission", submissionId = RouteParameter.Optional });

            routes.MapRoute(
                name: "SurveySummary",
                url: "Summary/{surveySlug}",
                defaults: new { controller = "Admin", action = "Summary" });

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

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Admin", action = "Index", id = UrlParameter.Optional });
        }
开发者ID:copdips,项目名称:CloudSurvey,代码行数:29,代码来源:RouteConfig.cs

示例7: RegisterRoutes

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

            // ex: api/technologies
            routes.MapHttpRoute(
               name: ControllerOnly,
               routeTemplate: "api/{controller}"
               );

            //  ex: api/project/1
            routes.MapHttpRoute(
                name: ControllerAndId,
                routeTemplate: "api/{controller}/{id}",
                defaults: null,
                constraints: new { id = @"^\d+$" }
            );

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

            routes.MapRoute(
                name: "Defaultss",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Upload", action = "Images", id = UrlParameter.Optional });
        }
开发者ID:ng-parth,项目名称:MvcWithNG,代码行数:30,代码来源:RouteConfig.cs

示例8: RegisterRoutes

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

            #region Web API Routes
            // Web API Session Enabled Route Configurations

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

            // Web API Stateless Route Configurations
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            #endregion

            #region MVC Routes
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
            #endregion
        }
开发者ID:linckon,项目名称:webapiangularjssecurity,代码行数:29,代码来源:RouteConfig.cs

示例9: RegisterRoutes

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

            //ASP.NET Web API Route Config
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

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

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

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
开发者ID:johnedu,项目名称:BackendMinTransporte,代码行数:29,代码来源:RouteConfig.cs

示例10: AddRoutes

        /// <summary>
        /// Adds the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        public void AddRoutes( RouteCollection routes )
        {
            routes.MapHttpRoute(
                name: "MetricValuesGetByMetricId",
                routeTemplate: "api/MetricValues/GetByMetricId/{metricId}",
                defaults: new
                {
                    controller = "MetricValues",
                    action = "GetByMetricId"
                } );

            routes.MapHttpRoute(
                name: "MetricValuesGetSummaryByMetricID",
                routeTemplate: "api/MetricValues/GetSummary",
                defaults: new
                {
                    controller = "MetricValues",
                    action = "GetSummary"
                } );

            routes.MapHttpRoute(
                name: "MetricValuesGetSeriesName",
                routeTemplate: "api/MetricValues/GetSeriesName/{metricId}/{seriesId}",
                defaults: new
                {
                    controller = "MetricValues",
                    action = "GetSeriesName"
                } );
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:33,代码来源:MetricValuesController.Partial.cs

示例11: RegisterRoutes

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

            routes.MapHttpRoute(
                name: "DomainApiById",
                routeTemplate: "api/LookupTable/id/{id}",
                defaults: new { controller = "LookupTable", action = "GetTablebyId" });

            routes.MapHttpRoute(
                name: "DomainApiByIdByEffectiveDate",
                routeTemplate: "api/LookupTable/id/{id}/{effectiveDate}",
                defaults: new { controller = "LookupTable", action = "GetTablebyIdByEffectiveDate" });

            routes.MapHttpRoute(
                name: "DomainApiByNameByGroup",
                routeTemplate: "api/LookupTable/{name}/{group}",
                defaults: new { controller = "LookupTable", action = "GetTableByNameByGroup" });

            routes.MapHttpRoute(
                name: "DomainApiByNameByGroupByEffectiveDateWithExpression",
                routeTemplate: "api/LookupTable/{name}/{group}/{effectiveDate}/{expression}");

            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 }
            );
        }
开发者ID:EmptyCubes,项目名称:More,代码行数:35,代码来源:RouteConfig.cs

示例12: RegisterRoutes

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

            routes.MapHttpRoute(
                name: "RootApi",
                routeTemplate: "api",
                defaults: new { controller = "root" }
            );

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

            routes.MapHttpRoute(
                name: "ClientSubscriptionsApi",
                routeTemplate: "api/clients/{clientId}/subscriptions/{subscriptionId}",
                defaults: new { subscriptionId = RouteParameter.Optional, controller = "clientsubscriptions" }
            );

            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 }
            );
        }
开发者ID:andlju,项目名称:entile-rewrite,代码行数:34,代码来源:Global.asax.cs

示例13: RegisterWebApiRoutes

        protected static void RegisterWebApiRoutes(RouteCollection routes)
        {
            if (routes == null) { throw new ArgumentNullException("routes"); }

            // http://localhost:12914/api/Config

            routes.MapHttpRoute(
                name: "allPackages",
                routeTemplate: "api/config/packages",
                defaults: new { controller = "Config", action = "GetAllPackages" });

            routes.MapHttpRoute(
                name: "GetPackagesByTag",
                routeTemplate: "api/config/packages/tag/{tag}",
                defaults: new { controller = "Config", action = "GetPackagesByTag" });

            routes.MapHttpRoute(
                name: "GetPackagesByName",
                routeTemplate: "api/config/packages/name/{name}",
                defaults: new { controller = "Config", action = "GetPackagesByName" });

            routes.MapHttpRoute(
                name: "GetLatestPackageByName",
                routeTemplate: "api/config/packages/latest/{name}",
                defaults: new { controller = "Config", action = "GetLatestPackageByName" });

            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
开发者ID:sayedihashimi,项目名称:khyber-pass,代码行数:32,代码来源:Global.asax.cs

示例14: RegisterRoutes

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

             //  routes.MapHttpAttributeRoutes();

            routes.MapHttpRoute(
                name: "DefaultApi1",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.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 }
            );

            routes.MapRoute(
               name: "checkout",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Checkout", action = "", id = "" }
               );

            routes.MapRoute(name: "test", url: "test/{controller}/{action}/{id}");
        }
开发者ID:natan1957,项目名称:mymentor-portal,代码行数:32,代码来源:RouteConfig.cs

示例15: RegisterRoutes

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

            // ex: api/tasks
            routes.MapHttpRoute(
                name: "ApiControllerOnly",
                routeTemplate: "api/{controller}"
            );

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

            // ex: api/lookups/enumdata
            routes.MapHttpRoute(
                name: "ApiControllerAction",
                routeTemplate: "api/{controller}/{action}"
            );

            //default mvc routing
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
开发者ID:arron-green,项目名称:TaskTrac,代码行数:31,代码来源:RouteConfig.cs


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