Eugene
Eugene

Reputation: 231

Swagger's page shows as my web page's start page

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;
        });

    }

Upvotes: 0

Views: 468

Answers (2)

Pavel Levchuk
Pavel Levchuk

Reputation: 757

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");
    });

Upvotes: 1

Andrei Tătar
Andrei Tătar

Reputation: 8295

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

Upvotes: 0

Related Questions