I can't understand how to teach to the web api and IIS to open the default page index.html of Swagger when navigate into. I'd like to redirect the default WebApi page to Swagger.
The WebApi is into "Default Web Site".
I tried the following:
if (app.Environment.IsDevelopment())
{
app.UseSwaggerUI();
}
else if (app.Environment.IsProduction())
{
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1.0/swagger.json", "v1.0");
options.RoutePrefix = "api/swagger";
});
}
IIS open the default "https://localhost/WebApi" showing
{"Message":"Value cannot be null. (Parameter 'key')","StatusCode":500}
Any suggestions?
Thanks
You can add the launchUrl to the launch.json file. You can configure a different launchUrl for every profile.
"TestWebApplication": {
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
try to remove the if else block.
On my Startup.cs inside Configure method I have just
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API NAME 1.0.0.0"));
then inside ConfigureService method:
services.AddSwaggerGen(c =>
{
c.CustomSchemaIds(x => x.FullName);
c.SwaggerDoc("v1",
new OpenApiInfo { Title = "MyApi", Version = "v1" });
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
it works on production and on development mode to with the follow url's
development:
production:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.