asp.net与Owin Swashbuckle基本配置在使用虚拟目录时找不到url

问题描述 投票:1回答:1

我一直在关注一些教程,包括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,我现在得到..

enter image description here

最后,如果我手动输入以下内容......

enter image description here

我的路线出现了。

我有什么想法配置这个?

asp.net asp.net-web-api2 swagger swashbuckle
1个回答
0
投票

问题2我修复了以下this FAQ

问题1仍然悬而未决,但我刚刚添加了自己的按钮来链接到获取Swagger UI的路径,所以我不再担心这个了。

© www.soinside.com 2019 - 2024. All rights reserved.