我目前正在 ASP.NET Core MVC 项目上进行编码。一切都工作得很好,直到突然间,当我编译并启动项目时,该页面不再托管在 root 上(它总是尝试打开 localhost:7053/index.html,调用时会抛出 404)。
自从 Program.cs 或 HomeController 工作以来,我没有对它进行任何更改。
我在这里尝试学习的唯一新概念是 OAuth2,我删除了它的代码,因为,正如刚才所说,它已经全部工作了。
这是我的Program.cs
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
app.UseCookiePolicy(new CookiePolicyOptions
{
Secure = CookieSecurePolicy.Always,
MinimumSameSitePolicy = SameSiteMode.None,
});
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
//DO NOT CHANGE
app.UseAuthentication();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
这就是我的索引视图功能:
public IActionResult Index()
{
return View();
}
我什至尝试了恢复 GitHub 提交更新,但错误仍然存在。一旦我托管它,一切都会顺利(部署时它工作得很好)。当提示 URL 时,可以毫无问题地访问所有其他控制器。
有人可以帮助我吗?
我已经尝试过: