ASP.NET网站改版后实现设置301永久重定向

54
补充展位
Pages_Weblog_Get#f5b30847-708a-462f-9016-ad4f00fa7529
文章摘要
此内容由人工摘要内容,并由AI根据文章内容进行润色
暂无内容

ASP.NET网站改版后实现301重定向

前段时间给网站做了整体改版(界面 开发框架 还有URL规则) 在保留了以前的链接的情况下新增了新的url链接规则,网上说是要做301重定向 不然影响收录 想着就做了301重定向

改版博客是在 .NET 5环境下开发的 以下是使用的301重定向的Action中的代码:

[Route("~/toolkit_{id}.html")]
public void Get(int Id)
{
            string url = $"http://{Request.Host.ToString()}/weblog/{Id}.html";//重定向的目标网址
            Response.StatusCode = 301;//状态设置为301
            Response.Headers.Add("Location", url);//设置地址链接
            Response.Headers.Add("Cache-Control", "no-cache");
            Response.Redirect(url, true);
}
补充展位 Pages_Weblog_Get#0
补充展位 Pages_Weblog_Get#1
补充展位 Pages_Weblog_Get#2
专题推荐
暂无内容
补充展位 Pages_Weblog_Get#3