【发布时间】:2023-04-03 22:05:02
【问题描述】:
我需要更改项目的默认起始页,但它不起作用。我正在使用
services.AddMvc().AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/Login/Index", "");
});
但是当项目启动时,它并没有转到LoginController。
更新。当我尝试将默认控制器更改为 LoginController 时,它会合并到主模板中,而无需在剃须刀页面上设置
Layout。
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages().AddRazorRuntimeCompilation();
services.AddControllersWithViews();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/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.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Login}/{id?}");
});
}
【问题讨论】:
-
this question 的答案可能会有所帮助
-
不行!
-
它不会转到控制器,因为您发出的调用是针对 Razor 页面,而不是 mvc。
-
我该如何解决这个问题?
-
你的应用是 MVC 还是 Razor Pages?
标签: c# asp.net-core