【问题标题】:Why wont .NET 6 load index.html unless I add /index.html to the URL [duplicate]为什么.NET 6 不会加载 index.html 除非我将 /index.html 添加到 URL [重复]
【发布时间】:2022-01-01 21:42:57
【问题描述】:

我正在使用 .NET 6 中的 web api。一切都按预期工作。但是,我正在尝试在 wwwroot 下加载一个简单的 HTML/CSS 登录页面。

我想补充一点,我从来没有遇到过这个问题,使用 .NET 3.0 或 .NET 5 具有类似的配置。

我有我的 Program.cs

app.UseSwagger();
app.UseSwaggerUI();    
app.UseHttpsRedirection();    
app.UseStaticFiles();    
app.UseAuthorization();    
app.MapControllers();    
app.Run();

现在,如果我要手动访问 localhost/index.html,我会在本地以及部署在 azure Web 应用程序上时获得登录页面。

但是,如果到达 localhost(或已部署的 Web 应用程序),index.html 将不会像在旧版本的 .NET 中那样加载。

是我遗漏了什么还是这像是一个错误?

此处提供完整项目 - https://github.com/Jay-study-nildana/CSharpForStudents/tree/main/WebApiDotNet6/DotNet6APIEFCoreSQLite

注意:我看过另一个类似的问题。我想,不一样。

MVC 6, .NET Core RC2 Rewrite to index.html on non /api urls

【问题讨论】:

标签: c# asp.net-core static-files .net-6.0 asp.net-core-6.0


【解决方案1】:

你需要在控制器方法中定义路由和视图

return View();

【讨论】:

  • 不,他们想要提供静态文件,而不是 Home/Index.cshtml 视图。
  • 也就是说,我理解错了。
猜你喜欢
  • 2018-02-03
  • 2012-02-24
  • 2016-10-13
  • 2015-01-20
  • 2021-12-02
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 2017-09-09
相关资源
最近更新 更多