I created a new Blazor Server project and added SwaggerUI and now the application searches for index.html as the start up object when I debug.
Interesting, I isolated the offending code to the routeprefix=""
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1.3");
c.DocExpansion(DocExpansion.None);
// c.RoutePrefix = "";
});
I run it once with the routeprefix ="" and the startup is set to index.html. Even when I comment it out, it still searches for the index.html page.
I did a few test and found that no relevant code was changed from the working and the non working.
I deployed the code to IIS and it seemed to work so I am guessing it maybe something to do with IIS express. I checked the configurations but did not find any think useful.
The code is the standard weather forecast test project created by default.
Here is the main program.
using BlazorAppIndexTest.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerUI;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddControllers();
builder.Services.AddSingleton<WeatherForecastService>();
//first line added
builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "My Service", Version = "v1" }); });
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
//second line added
app.UseSwagger();
//third line added
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1.3");
c.DocExpansion(DocExpansion.None);
// c.RoutePrefix = "";
});
app.Run();
Anyone have any ideas of how to fix this or force the application to start with razor page.
AS usual, I found the answer after I posted the question.
Clearing the browser cache worked. I swear I tried that before.
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.