重定向()与永久重定向()在ASP.NET MVC [英] Redirect() vs RedirectPermanent() in ASP.NET MVC

查看:143
本文介绍了重定向()与永久重定向()在ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我之间的差异重定向()永久重定向()。我读了一些文章,但我不明白的时候一定要使用重定向()永久重定向()。您可以显示一个块的例子。

Whats difference between Redirect() and RedirectPermanent(). I had read some articles, but I don't understand when we must use Redirect() and RedirectPermanent(). Can you show a pieces of example.

推荐答案

这两者之间的基本区别是,永久重定向将浏览器的 HTTP 301 (永久移动)状态code,而重定向将发送 HTTP 302 状态code。

The basic difference between the two is that RedirectPermanent sends the browser an HTTP 301 (Moved Permanently) status code whereas Redirect will send an HTTP 302 status code.

使用永久重定向如果资源已经被永久移动,将不再在其previous位置访问。大多数浏览器会缓存这个响应,而无需再次请求原始资源自动执行重定向。

Use RedirectPermanent if the resource has been moved permanently and will no longer be accessible in its previous location. Most browsers will cache this response and perform the redirect automatically without requesting the original resource again.

使用重定向如果资源可以在未来的同一位置(URL)是可用的。

Use Redirect if the resource may be available in the same location (URL) in the future.

示例

让我们说,你有你的系统的用户。你也有一个选项,删除现有用户。您的网站有一个资源 /用户/用户ID {}​​ 显示给定用户的详细信息。如果用户已被删除,您必须重定向到 /用户/不 - 不存在页。在这种情况下:

Let's say that you have users in your system. You also have an option to delete existing users. Your website has a resource /user/{userid} that displays the details of a given user. If the user has been deleted, you must redirect to the /user/does-not-exist page. In this case:

如果用户将绝不会重新恢复,你应该使用永久重定向这样浏览器就可以直接到 /用户/不 - 不存在在后续请求,即使该URL指向 /用户/用户ID {}​​

If the user will never be restored again, you should use RedirectPermanent so the browser can go directly to /user/does-not-exist in subsequent requests even if the URL points to /user/{userid}.

如果用户可能未删除了某个未来,你应该使用普通的重定向

If the user may be un-deleted sometime in the future, you should use a regular Redirect.

这篇关于重定向()与永久重定向()在ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆