Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 在Azure Web API中调用UseSwagger时出错_Asp.net Core_Asp.net Web Api2_Swagger Ui - Fatal编程技术网

Asp.net core 在Azure Web API中调用UseSwagger时出错

Asp.net core 在Azure Web API中调用UseSwagger时出错,asp.net-core,asp.net-web-api2,swagger-ui,Asp.net Core,Asp.net Web Api2,Swagger Ui,我已经创建了VS2015和.Net核心Web API项目。 我在下面的例子中 我已经安装了Swashback.AspNetCore,下一步尝试编码,但在使用UseSwagger时出错。请告诉我 /* Startup.cs */ using System; using System.Collections.Generic; using System.Linq; using Microsoft.Owin; using Owin; using Swashbuckle.AspNetC

我已经创建了VS2015和.Net核心Web API项目。 我在下面的例子中

我已经安装了Swashback.AspNetCore,下一步尝试编码,但在使用UseSwagger时出错。请告诉我

/* Startup.cs */
using System;  
using System.Collections.Generic;  
using System.Linq;  
using Microsoft.Owin;  
using Owin;  
using Swashbuckle.AspNetCore.Swagger;  
using Microsoft.Extensions.DependencyInjection;  

[assembly: OwinStartup(typeof(TestApi.Startup))]

namespace TestApi
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
        ConfigureAuth(app);

        /*use swagger added by me*/
        app.UseSwagger();      /*ERROR:iAppBuilder does not contain definition for UseSwagger…*/
        app.UseSwaggerUI(c =>. /*ERROR :iAppBuilder does not contain definition for UseSwaggerUI…*/
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "Accounts API V1");  
        });  

    }

    //Add framework services by me
    public void ConfigureServices(IServiceCollection services) {
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "AcccountsAPI", Version = "v1" });  
        });  

        }
    }
}

我根据您的代码假设您正在使用.Net Core v1.1,我就是这样做的:

    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        WebApiConfig.Register(config);
        config.EnableSwagger(c =>
        {
            c.SingleApiVersion("v1", "WebAPI");
            c.IncludeXmlComments(GetXmlCommentsPath());
            c.ResolveConflictingActions(x => x.First());

        }).EnableSwaggerUi();
    }

    protected static string GetXmlCommentsPath()
    {
        return System.String.Format($@"{0}\bin\MyApi.XML",
                System.AppDomain.CurrentDomain.BaseDirectory);
    }