ilM*_*ion 4 c# asp.net-web-api swagger swagger-ui
我正在使用Microsoft Web API 2和SwaggerUi开发RESTful Web服务.
我删除了默认的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);
}
Run Code Online (Sandbox Code Playgroud)
这是我的SwaggerConfig.cs代码:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "MyNamespace.WebApi");
})
.EnableSwaggerUi(c =>
{});
Run Code Online (Sandbox Code Playgroud)
在此操作之后,我无法像下面的图像一样查看swagger上的操作:
拜托,你能帮帮我吗?
非常感谢
我已经解决了改变:
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);
}
Run Code Online (Sandbox Code Playgroud)
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 =>
{
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在https://github.com/domaindrivendev/Swashbuckle/issues/196上找到了解决方案
归档时间: |
|
查看次数: |
5122 次 |
最近记录: |