gpt4 book ai didi

asp.net-core - 在 ASP.NET CORE 中设置不同的主页 URL

转载 作者:行者123 更新时间:2023-12-04 20:30:17 26 4
gpt4 key购买 nike

在 ASP.NET Core 项目中,我有以下路线:

public class AboutController : Controller {

[HttpGet("about-us")]
public IActionResult Index() => View();

}

如何使这个网址成为网站的默认主页?

因此,当我访问 www.mydomain.com 时,我会自动重定向到 www.mydomain.com/about-us

这在 ASP.NET Core 中是可能的还是我需要在域 DNS 上执行此操作?

最佳答案

您可以使用 URL Rewriting Middleware 添加重定向规则:

var option = new RewriteOptions();
option.AddRedirect("^$", "about-us");

app.UseRewriter(option);

关于asp.net-core - 在 ASP.NET CORE 中设置不同的主页 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47911677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com