Home > database >  swagger/index.html shows a blank page (asp.net core)
swagger/index.html shows a blank page (asp.net core)

Time:09-08

I am writing a web api in ASP.NET CORE for the data models Package and Content. They are originally from MSSQL so I connected to the db server successfully. After writing http requests in the controllers, when I ran the project to test, it takes me to swagger/index.html that shows a blank page, I have no idea why.

enter image description here Here is my program.cs

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");

//OperationsContext is a db context that has both content and package dbcontext
builder.Services.AddDbContext<OperationsContext>(x => x.UseSqlServer(connectionString));
/*builder.Services.AddMvc();
builder.Services.AddHttpContextAccessor();*/

builder.Services.AddScoped<IContentRepository, ContentRepository>();
builder.Services.AddScoped<IPackageRepository, PackageRepository>();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseSwagger();

app.UseSwaggerUI(c =>
{
    if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
    {
        c.SwaggerEndpoint("/swagger/Package/swagger.json", "Package v1");
    }
    else
    {
        // To deploy on IIS
        c.SwaggerEndpoint("/swagger/Package/swagger.json", "Package v1");
    }

});
app.UseHttpsRedirection();
app.UseAuthorization();    
app.MapControllers(); 
app.Run();

I am assuming it's the program.cs, but there are no issues when I ran it. Does anyone know why?

CodePudding user response:

Swagger UI does not support Internet Explorer. Use Chrome, Firefox, Safari, or Edge instead.

  • Related