gpt4 book ai didi

asp.net - asp.net如何实现301永久重定向

转载 作者:可可西里 更新时间:2023-11-01 16:26:04 26 4
gpt4 key购买 nike

你能告诉我,如何在 asp.net 中进行 301 永久重定向吗?

我已经在 Global.asax 文件中编写了代码,但我的 Web 客户端说它不起作用,

我在 Global.asax 文件中编写了以下代码:

    protected void Application_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(
"http://lsatfreedom.com"))
{
HttpContext.Current.Response.Status =
"301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
Request.Url.ToString().ToLower().Replace(
"http://lsatfreedom.com",
"http://www.lsatfreedom.com"));
}

}

有用吗?请帮忙。

谢谢

最佳答案

首先尝试查看此重定向是否适用于页面加载。如果是,则尝试使用 Begin_Request。

希望这能给你一些线索:

private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}

关于asp.net - asp.net如何实现301永久重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4755407/

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