I am using Swagger as my API docs system. I have installed all necessary tools and it is working properly. However the problem I experience is that my start page shows Swagger's page. Any suggestions how can I resolve this issue?
Here is my Startup.cs - config file
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = string.Empty;
});
}
You should remove prefix. Here's how I do it in my project:
// ConfigureServices
services.AddMvc();
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("path", new Info() { Title = "My API V1", Version = "v1" });
});
// Configure
app.UseAuthentication():
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/path/swagger.json", "My API V1");
});
The startup page is not something you configure in code. It's something you configure in the project properties from visual studio, since it only affects your development process.
You can find it by right clicking on the project, opening project properties and going to startup options: https://msdn.microsoft.com/en-us/library/ms178730.aspx#Anchor_1
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.