Redirect() vs RedirectPermanent() in ASP.NET MVC

 

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.

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.

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

Example

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:

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.

Note that  RedirectPermanent can be annoying while debugging because the second time you click, controller's action will be skipped and no break point are reached in the original function if it redirect elsewhere. That is unless you empty your cache before every click.

转载于:https://www.cnblogs.com/Jayesslee/p/9299063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值