开发者

Redirect to previous url?

I was just won开发者_运维知识库dering how in I can find the previously visited url for a session?

So after a user does something I can redirect them to that URL.

Is there any standard way to do this? Otherwise I was going to add some overrides to Global.asax and use a session variable to store URL history.


Request.UrlReferrer might be what you want, but you might want to think about using AJAX or passing the url as a parameter...


The above answer is totally correct, although in certain cases you cannot pass the URL along the query string, for instance when the URL is masked. In this case the right way is Request.UrlReferrer. The problem with using a session variable is it might expire and cause unreliable behavior. Or if you have more than one session active or mirrored servers, it wont work at all.

In general its a poor idea to use session variables in MVC when it can be avoided. The solution I went with was using JavaScript to get the previous URL and passing that up in the view model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜