我需要相同的内容(具有不同网址的同一页面)喜欢: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
我想念什么吗?
[Route("/Home/Privacy")]
[Route("/Home/Privat")]
您也可能会在[Routing to controller actions in ASP.NET Core中找到heplpfull
1。内容结构:
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()
{
}
}