我一直在关注一些教程,包括this one,通过Swashbuckle添加Swagger。
从各个帖子中,我在启动时更改了以下内容。
//GlobalConfiguration.Configuration
// .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
// .EnableSwaggerUi();
HttpConfiguration httpConfig = new HttpConfiguration();
SwaggerConfig.Register(httpConfig);
WebApiConfig.Register(httpConfig, unityContainer);
app.UseWebApi(httpConfig);
在我的SwaggerConfig.cs中,我有......
//[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace Micromine.MyApp
{
public class SwaggerConfig
{
public static void Register(HttpConfiguration httpConfig)
{
httpConfig
.EnableSwagger(c =>
{
c.RootUrl(req => SwaggerDocsConfig.DefaultRootUrlResolver(req));
c.SingleApiVersion("v1", "MyCompany.MyApp");
c.IncludeXmlComments(string.Format(@"{0}\bin\myapp.xml", System.AppDomain.CurrentDomain.BaseDirectory));
})
.EnableSwaggerUi(c =>
{
});
}
问题1。
当我运行我的应用程序时,我有以下根路由...
http://localhost/myapp/
现在,如果我尝试浏览招摇,即输入
http://localhost/myapp/swagger
它重定向到http://localhost/swagger/ui/index
,即它在路径中没有myapp
。
问题2
如果我现在手动浏览到http://localhost/myapp/swagger/ui/index
,我现在得到..
最后,如果我手动输入以下内容......
我的路线出现了。
我有什么想法配置这个?
问题2我修复了以下this FAQ。
问题1仍然悬而未决,但我刚刚添加了自己的按钮来链接到获取Swagger UI的路径,所以我不再担心这个了。