tags:

views:

807

answers:

3

I have a requirement which needs me to redirect an user to previous page on his browsing history. I am using ASP.net MVC 1.0. I do NOT want to use javascript to achieve this. Any pointers?

+1  A: 

You can take a parameter "returnUrl" in your action, and then return a RedirectResult. It should do.

For info, take a look at the Account controller, from the default template ASP.NET MVC project on VS2008.

Bruno Reis
this will only work for pages within his site.
Darko Z
+1  A: 

You can use the Request.UrlReferrer property to render out a link. Maybe like this:

<a href="<%= Request.UrlReferrer %>">Back</a>
Darko Z
This will not work if the browser blocks the referrer... and many people seem to do that nowadays!
Bruno Reis
I've never had that problem to be honest - i guess the OP will have to decide whether this is a risk for his site though
Darko Z
It's fairly common to block the referrer when you are behind a corporate firewall.
Nathan
A: 

THis is pretty simple. Use Request.UrlReferrer.ToString()