I have created a webAPI project and I would like to start hosting it in IIS.
The method in the controller looks like this:
[TokenAuthentication]
[HttpGet]
[Authorize(Roles=Roles.PING)]
[Route("~/Ping")]
public DateTime Ping()
{
return DateTime.UtcNow;
}
My WebApiConfig looks like this:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
config.MapHttpAttributeRoutes();
GlobalConfiguration.Configuration.Filters.Add(new ValidateModelAttribute());
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
}
}
When I run the project via visual studio, and go to the link http://localhost:53722/ping I get an unauthorized response which is what I expect.
When I put the website on IIS in an applicaion with the virtual path "/Account" I get a 404 response and it is trying to use the StaticFile Handler.
Through searching online I have runAllManagedModulesForAllRequests set to true. I have also found Configure ASP.NET Web API application as a Virtual Directory under ASP.NET MVC application which seems like the "/Account/" should not be interfering with the route.
I can not put the API at the route directory because I will be running multiple microservices under the same site.
How would I get the route to work using the virtual directory?
Thanks, Steven
Each site should be running as an Application and not a Virtual Directory (and ideally with each having its own application pool).
Out of the box you would normally go for
[Route("ping")]
This would give you a url of http://blah.com/ping
If you are running this api in a sub folder/application then it maybe something like http://blah.com/subapp/ping
This is all i have...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.