【发布时间】:2019-02-03 11:56:50
【问题描述】:
我使用 Swagger 向 Microsoft Azure Web 应用程序发布了一个 ASPNETCORE WebAPI,它运行良好。但是,我的 API 将文件上传到一个文件夹。当我尝试通过 URL 访问上传的文件时,应用程序会将我重定向到 Swagger 主页。所以我无法访问上传的文件。我该如何解决?
例如: 我的 API URL 是
http://api.guarda.digital/swagger/
上传的文件在
http://api.guarda.digital/uploads/1535281344287289147145.jpg
如果您访问文件 url,您将被重定向到 swagger 主页。
这是我的Startup.cs 配置:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "Guarda Digital API", Version = "v1" });
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Guarda Digital API V1");
});
app.Run(async (context) => await Task.Run(() => context.Response.Redirect("/swagger")));
}
还有位于/site/wwwroot内部的web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\GD.WebAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
【问题讨论】:
标签: .net asp.net-core swagger azure-web-app-service