2016-01-23 83 views
0

我想用Swagger和Web API一起使用。我只是使用隨Visual Studio一起安裝的ASP.NET 4.6模板中的「Azure API App」模板,其中包括Swashbuckle.CoreSwaggerConfig.cs。該API工作正常(我能成功地稱呼它),但如果我嘗試去「http://mybaseurl/swagger/」,我得到這個錯誤:Swagger給我HTTP錯誤403.14 - 禁止

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

好像揚鞭是沒有得到加載或東西。其他人之前得到這個?我似乎無法解決這個問題。謝謝,請讓我知道我是否可以提供更多細節。

這裏是我的SwaggerConfig.cs是什麼樣子:

[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")] 

namespace With.Api 
{ 
    public class SwaggerConfig 
    { 
     public static void Register(HttpConfiguration config) 
     { 
      var thisAssembly = typeof(SwaggerConfig).Assembly; 

      config.EnableSwagger(c => 
      { 
       c.SingleApiVersion("v1", "With.Api"); 
      }) 
      .EnableSwaggerUi(); 
     } 
    } 
} 
+0

嘗試啓用'目錄Browsing'在IIS本網站。 – Martin

+0

沒有運氣。該文件夾實際上並不存在,路由器應該將我路由到swagger-ui –

+0

您可以通過導航到swagger/docs或swagger/{version}/docs來獲取json轉儲嗎? –

回答

0

嘗試用此URL,而不是http://mybaseurl/swagger/ui/indexhttp://mybaseurl/swagger/

+0

與之前相同的結果 –

+0

是否爲網站啓用了匿名身份驗證? – Martin

+0

你的應用程序工作正常,除了Swagger? – Martin

2

我有同樣的問題。當我將應用程序部署到Azure時它運行良好,但是當我在本地啓動它時,Swagger不會像上面所述那樣顯示。 恢復到以前的版本我知道以前工作也沒有幫助,所以它似乎與IIS快遞有關。我不完全確定是什麼導致了這個問題(我改變了一些與SSL相關的設置),但是當我刪除.vs文件夾(其中包含applicationhost.config文件)並重新啓動Visual Studio時,它再次開始工作。

0

由於某種原因改變的Application_Start調用的順序,將解決這個問題,這是我有:

AreaRegistration.RegisterAllAreas(); 
GlobalConfiguration.Configure(WebApiConfig.Register); 
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
**GlobalConfiguration.Configure(SwaggerConfig.Configure);** 
RouteConfig.RegisterRoutes(RouteTable.Routes); 
BundleConfig.RegisterBundles(BundleTable.Bundles); 
XmlConfigurator.Configure(); 
相關問題