SwaggerUI导致Blazor应用程序中IIS Express上的Index.html启动副作用

ajsxfq5m  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(148)

我创建了一个新的Blazor服务器项目并添加了SwaggerUI,现在应用程序在我调试时搜索index.html作为启动对象。
有趣的是,我将违规代码隔离到routeprefix="”

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1.3");
    c.DocExpansion(DocExpansion.None);
   // c.RoutePrefix = "";
});

我使用routeprefix ="”运行了一次,启动设置为index.html。即使我将其注解掉,它仍然搜索index.html页面。
我做了一些测试,发现没有相关的代码从工作和非工作的变化。
我把代码部署到IIS上,它看起来可以工作,所以我猜它可能与IIS Express有关。我检查了配置,但没有发现任何有用的东西。
该代码是默认创建的标准天气预报测试项目。
这里是主程序。

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

任何人都有任何想法,如何修复这个或迫使应用程序开始与剃刀页。

bybem2ql

bybem2ql1#

和往常一样,我在发布问题后找到了答案。
清除浏览器缓存成功了。我发誓我以前试过。

相关问题