ASP.NET Core 2.2的页面名称

问题描述 投票:0回答:2

我需要相同的内容(具有不同网址的同一页面)喜欢:http://localhost:59810/Home/Privacyhttp://localhost:59810/Home/Privat

尝试将以下内容添加到品牌限定的2.1项目中的启动“ ConfigureServices”中

      services.AddMvc()
               .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
               .AddRazorPagesOptions(options => {
                   options.Conventions.AddPageRoute("/Privacy", "/Privat");

               });

I also did try:

      services.AddMvc()
               .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
               .AddRazorPagesOptions(options => {
                   options.Conventions.AddPageRoute("/Home/Privacy", "/Home/Privat");

               });

但是无法正常工作,我仍然收到404:http://localhost:59810/Home/Privat

我想念什么吗?

c# routing asp.net-core-mvc
2个回答
0
投票
[Route("/Home/Privacy")] [Route("/Home/Privat")]

您也可能会在[Routing to controller actions in ASP.NET Core中找到heplpfull


0
投票
这里是一个简单的演示,如下所示:

1。内容结构:

enter image description here

2.Startup.cs:

public void ConfigureServices(IServiceCollection services) { services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Home/Privacy", "/Home/Privat"); }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(); }

3.Privacy.cshtml.cs:

public class PrivacyModel : PageModel
{
    public void OnGet()
    {
    }
}

4。结果:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.