2016-12-14 66 views
1

我正在開發使用Microsoft Web API 2和SwaggerUi的RESTful Web服務。爲什麼在owin實施之後,招搖即止?

我已經刪除了默認的Global.asax,並使用OWIN配置了我的Web API。這是我的Startup.cs代碼:

public void Configuration(IAppBuilder app) 
    { 
     HttpConfiguration config = new HttpConfiguration(); 

     WebApiConfig.Register(config); 

     config.MessageHandlers.Add(new JWTAuthenticationHandler() { StopPipelineHandling = true }); 

     config.Filters.Add(new MyActionFilter()); 

     SwaggerConfig.Register(); 

     app.UseWebApi(config); 

    } 

這是我的SwaggerConfig.cs代碼:

 GlobalConfiguration.Configuration 
      .EnableSwagger(c => 
       { 
        c.SingleApiVersion("v1", "MyNamespace.WebApi"); 
       }) 
      .EnableSwaggerUi(c => 
       {}); 

此操作之後,我無法查看招搖的操作,如下面的圖片:

Swagger screen without actions

請問,你能幫助我嗎?

謝謝很多

+2

我建議您使用瀏覽器開發人員工具(F12)查看從您的Web API返回的內容。很可能你得到了錯誤狀態代碼,然後你必須修復。 –

+0

嗨馬丁,我試過了,我可以正確使用我的API。 – ilMattion

+0

試試這個,而不是使用「GlobalConfiguration.Configuration」將httpConfiguration傳遞給swagger寄存器。 公共靜態無效寄存器(HttpConfiguration配置) { config.EnableSwagger(C => { c.SingleApiVersion( 「V1」, 「MyNamespace.WebApi」);}).EnableSwaggerUi();} – Prashant

回答

2

我已經解決改變:

Startup.cs

public void Configuration(IAppBuilder app) 
{ 
    HttpConfiguration config = new HttpConfiguration(); 

    // Swagger 
    SwaggerConfig.Register(config); 

    // Authentication token 
    ConfigureOAuth(app); 

    // SignalR configuration 
    ConfigureSignalR(app); 

    // Register routes 
    WebApiConfig.Register(config); 

    // Allow cross-domain requests 
    app.UseCors(CorsOptions.AllowAll); 

    app.UseWebApi(config); 
} 

SwaggerConfig.cs

using Swashbuckle.Application; 
using System.Web.Http; 

namespace Name.API 
{ 
    public class SwaggerConfig 
    { 
      public static void Register(HttpConfiguration config) 
      { 
       config.EnableSwagger(c => 
       { 
        c.SingleApiVersion("v1", "Name.API"); 
       }) 
      .EnableSwaggerUi(c => 
       { 
       }); 
     } 
    } 
} 

我已經找到https://github.com/domaindrivendev/Swashbuckle/issues/196解決方案