gpt4 book ai didi

c# - Swagger 未显示在 Azure 上

转载 作者:行者123 更新时间:2023-12-03 04:49:32 30 4
gpt4 key购买 nike

我有以下启动文件:

    public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});


services.AddMvc()
.AddFluentValidation()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Title = "Name Application Api",
Version = "v1",
Contact = new Contact
{
Name = "A B",
Email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1d4dcd0d8ddf1d4dcd0d8dd9fd2dedc" rel="noreferrer noopener nofollow">[email protected]</a>"
}
});

c.DescribeAllEnumsAsStrings();
c.DescribeStringEnumsInCamelCase();

//c.OperationFilter<SwaggerAuthResponsesOperationFilter>();

// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);

// enable the annotations on Controller classes [SwaggerTag]
c.EnableAnnotations();
});

services.AddMvcCore().AddApiExplorer();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});

app.UseSwagger();

// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Support Application API V1");
c.DocumentTitle = "Support Application Api";
});
}

当我尝试在本地打开 swagger 页面时,它工作正常 https://localhost:44341/swagger/index.html但是当我将其发布到 Azure 时,我得到了

This page isn’t working

drugalcohol.azurewebsites.net is currently unable to handle this request.

HTTP ERROR 500

服务计划为 B1 定价层。

出了什么问题?

最佳答案

您的项目中似乎未配置 XML 生成步骤,这就是为什么在代码行 c.IncludeXmlComments(xmlPath); 执行中应用程序会使用 Http 500 状态代码进行响应。

要生成 XML 注释,您需要确保选中项目构建属性中的“XML 文档文件”选项。

enter image description here

关于c# - Swagger 未显示在 Azure 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58356908/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com