ASP.net web api 2 Route-Attribute not working

前端 未结 7 1887
野性不改
野性不改 2021-01-19 17:52

I\'ve the following problem, my route attribute is not working.

I have the following action:

[HttpGet]
[Route(\"~api/admin/template/{fileName}\")]
pu         


        
7条回答
  •  滥情空心
    2021-01-19 18:38

    You have to call MapHttpAttributeRoutes() so that the Framework will be able to walk through your attributes and register the appropriate routes upon application start:

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
    
            // you can add manual routes as well
            //config.Routes.MapHttpRoute(...
        }
    }
    

    See MSDN

提交回复
热议问题