2016-12-05 47 views
0

我创建了一个项目的WebAPI,我想开始在IIS托管它。使用RouteAttribute和IIS应用程序使404错误

在控制器的方法是这样的:

[TokenAuthentication] 
    [HttpGet] 
    [Authorize(Roles=Roles.PING)] 
    [Route("~/Ping")] 
    public DateTime Ping() 
    { 
     return DateTime.UtcNow; 

    } 

我WebApiConfig看起来是这样的:

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 } 
     //); 
    } 
} 

当我运行通过Visual Studio中的项目,并转到链接http://localhost:53722/ping我得到这是我所期望的未经授权的回应。

当我把网站上的IIS在广告应用程式与虚拟路径“/帐户”我得到一个404响应,并试图使用StaticFile处理程序。

通过网上搜索我必须设置为true runAllManagedModulesForAllRequests。我也发现Configure ASP.NET Web API application as a Virtual Directory under ASP.NET MVC application这看起来像“/帐户/”不应该干涉路线。

我不能把API的路线目录,因为我将在同一个站点下运行多个微服务。

我该如何获得路线使用虚拟目录工作?

感谢, 史蒂芬

回答

0

每个站点应该作为应用程序运行,而不是一个虚拟目录(理想情况下,每个有它自己的应用程序池)。

开箱即用你通常会去

[Route("ping")] 

这将使你的http://blah.com/ping 一个URL如果您在子文件夹/应用程序中运行这个API那么它可能像http://blah.com/subapp/ping

这就是我所有...

相关问题