Reputation: 9013
I have the following Startup file:
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 = "[email protected]"
}
});
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";
});
}
It works fine, when I try to open swagger page on local https://localhost:44341/swagger/index.html But when I publish it to Azure I get
This page isn’t working
drugalcohol.azurewebsites.net is currently unable to handle this request.
HTTP ERROR 500
Service Plan is B1 pricing tier.
What is wrong?
Upvotes: 0
Views: 590
Reputation: 10849
It seems that XML generation step is not configured in your project that's why on code line c.IncludeXmlComments(xmlPath);
execution the application responds back with Http 500 status code.
To generate the XML comments, you need to make sure that "XML documentation file" option in project's build property is checked.
Upvotes: 4