gpt4 book ai didi

asp.net-mvc - 从 Controller 操作返回 301 重定向

转载 作者:行者123 更新时间:2023-12-03 02:27:46 25 4
gpt4 key购买 nike

在 ASP.net MVC 上,让 Controller 返回 301 重定向到外部站点的“正确”方法是什么?

各种 RedirectTo-Function 似乎只返回我手动映射的相对链接或路由,但没有办法说“执行 301 重定向到 http://example.com ”。

我想我可以设置 Response.StatusCode 或使用 Response.Redirect,但这是 MVC 中应该完成的方式吗?或者是否有执行重定向的官方“正确方法”?

更新:同时,我为此编写了一个 ActionResult: PermanentRedirectResult

更新 2:自 ASP.net 4.0 起,永久重定向为 part of the Framework .

最佳答案

使用

Response.RedirectPermanent("http://www.google.com"); 

或者从 Controller 返回 ActionResult 类型:

return RedirectPermanent("http://www.google.com"); 

由ASP.net 4.0框架提供。

关于asp.net-mvc - 从 Controller 操作返回 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/217935/

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