Tomas Walek Tomas Walek - 1 month ago 6
ASP.NET (C#) Question

Defining a WebAPI route without the /api/{controller} prefix

I want to process requests in format without the /api/{Controller} prefix (e.g. www.myapp.com/download/image1.jpg) by a WebAPI controller method. Is it even possible or do I need do switch to MVC controller? I Defined the following route:

config.Routes.MapHttpRoute(
name: "Check",
routeTemplate: "download",
defaults: new { controller = "Download", action = "CheckAccess" });


but unfortunately it is not working, the controller doesn't even gets created (I have traces in the constructor)

Answer

Try attribute routing ( only available in web api 2)