我正在尝试使用.Net Core3.1构建一个带有内置应用程序接口的剃刀页面站点。一旦实现了Swashbuckle/Swagger/ ReDoc,我的主页/根页面就不再工作了(404),尽管ReDoc生成的页面可以。每次我运行这个项目时,它加载的是localhost:{port}/index.html而不是index.cshtml Razor页面。
有没有办法改变这个行为,让我的根url指向Razor索引文件?
下面是我在我的Startup.cs中做的事情:
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
//Misc other config
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "API Documentation",
Version = "v1",
Description = File.ReadAllText($"{AppContext.BaseDirectory}\\wwwroot\\DocumentationMarkdown.txt")
});
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath, true);
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
app.UseSwagger();
app.UseReDoc(c =>
{
c.SpecUrl("/swagger/v1/swagger.json");
c.EnableUntrustedSpec();
c.ScrollYOffset(10);
c.HideHostname();
c.HideDownloadButton();
c.ExpandResponses("200,201");
c.NoAutoAuth();
c.PathInMiddlePanel();
c.HideLoading();
c.NativeScrollbars();
c.SortPropsAlphabetically();
c.DocumentTitle = "API Documentation";
});
}我的页面结构是这样的:
Pages
Shared
_Layout.cshtml
_ViewStart.cshtml
Index.cshtml
Index.cshtml.cs发布于 2020-07-02 04:20:43
好吧,我想通了.基于这篇文章,Aspnet core 2.2 default route changed to "~/index.html" after installing Swashbuckle.AspNetCore package
我添加了RoutePrefix,这是我以前做过的,但问题当然是浏览器缓存。一次硬重置后,我就可以做生意了。还需要注意的是,上面的方法适用于.Net核心3.1和更低版本。
https://stackoverflow.com/questions/62684456
复制相似问题