ASP.net web api 2 Route-Attribute not working

前端 未结 7 1957
野性不改
野性不改 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:46

    Try this routing in your WebApiConfig

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

    You have to add RoutePrefix.

提交回复
热议问题