2017-08-24 104 views

回答

2

您可以将路径添加到的EnableSwaggereUi通话, 例如: -

SwaggerConfig.Register(HttpConfiguration config) 
{ 
    config.EnableSwaggerUi("apihelp/{*assetPath}", c => 
    ... // following lines omitted 
} 

然后,您可以调用UI与URL http://localhost:56081/apihelp/index

https://github.com/domaindrivendev/Swashbuckle#custom-routes以供参考。

请注意:默认设置'swagger'自动重定向到'swagger/ui/index',但是当您使用'apihelp'时,此自定义设置不会自动重定向到'apihelp/index'。 实现了自动重定向您可以添加路线WebApiConfig

config.Routes.MapHttpRoute(
    name: "Swagger UI", 
    routeTemplate: "apihelp", 
    defaults: null, 
    constraints: null, 
    handler: new RedirectHandler(message => message.RequestUri.ToString().TrimEnd('/'), "/index")); 

重定向代​​码是基于v.karbovnichy的答案How to redirect from root url to /swagger/ui/index?