0

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Missing/incorrect configs, most likely. Does your code contain the string VOMPackage?
yes it does. I mistyped it on the comment but everything is correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.