gpt4 book ai didi

c# - 301错误和样本测试

转载 作者:行者123 更新时间:2023-12-03 08:35:55 25 4
gpt4 key购买 nike

如何在asp.net中测试本地主机中的301错误。我添加了global.asax页并编写了代码

 void Application_BeginRequest(object sender, EventArgs e)
{
const string www = "http://www.localhost/test";
const string redirect = "http://localhost/test/";
string request = HttpContext.Current.Request.Url.ToString();

if (request.StartsWith(www, StringComparison.InvariantCultureIgnoreCase))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
redirect + request.Substring(www.Length));
}
}

并通过虚拟目录配置本地主机,但是我无法在配置时看到任何更改。

最佳答案

为什么不改用 HttpResponse.RedirectPermanent() ?它内置于:

HttpContext.Current.Response.RedirectPermanent(redirectUrl); 

关于c# - 301错误和样本测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6648591/

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