ASP.NET Web Api Routing Customization

前端 未结 4 1667
刺人心
刺人心 2021-02-19 11:38

I have WebApi controllers that end with the \"Api\" suffix in their names (For ex: StudentsApiController, InstructorsApiController). I do this to easily differentiate my MVC con

4条回答
  •  盖世英雄少女心
    2021-02-19 12:14

    Following Youssef's comment on muruug's answer would look something like this

    public class ApiControllerSelector : DefaultHttpControllerSelector
    {
        public ApiControllerSelector (HttpConfiguration configuration) : base(configuration) { }
    
        public override string GetControllerName(HttpRequestMessage request)
        {
            return base.GetControllerName(request) + "api";
        }
    }
    

提交回复
热议问题