如何在Visual Studio 2017社区RC中的本地IIS上发布ASP.NET核心WEB API项目?

时间:2017-03-17 06:07:39

标签: iis visual-studio-2017 asp.net-core-webapi

我想在IIS上使用swagger发布ASP.NET Core WebAPI Project。我想在本地计算机上使用IP地址运行项目。

我的电脑的配置是: Visual Studio 2017社区RC Windows 10 IIS

请帮帮我。

1 个答案:

答案 0 :(得分:2)

你试过"this one (docs.microsoft.com)"吗? 这对我有帮助。不要忘记为您将要使用的应用程序池标识配置身份验证和访问您的站点物理路径。

UPD(回复评论): 如果你正在使用Swashbuckle.AspNetCore包,你可以在你的ConfigureServices(IServiceCollection服务)中试试这样的东西:

// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
    var info = new Info
    {
        Title = "My web API",
        Version = "v1.0",
        Contact = new Contact()
        {
            Email = "foo@gmail.com",
            Name = "Denis",
            Url = "https://stackoverflow.com"
        },
        Description = "My API"
    };
    c.SwaggerDoc("v1.0", info);
    var basePath = AppContext.BaseDirectory; // this is not equal to wwwroot folder due to WebHostBuilder settings
    var xmlPath = Path.Combine(basePath, "MyApi.xml");
    c.IncludeXmlComments(xmlPath);
});

在Configure(IApplicationBuilder应用程序,IHostingEnvironment环境,ILoggerFactory loggerFactory)中:

// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();

// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "My web API v1.0");
    c.EnableDeepLinking();
});