views:

32

answers:

1

I need to implement back functionality in my project, for this what i am doing that i am maintain last url in ViewData["RetUrl"] and on next page i am getting previous url from that ViewData["RetUrl"].on this way i had implemented this functionality.This idea is failed when level of pages increased i mean page1>page2>page3, no way to back page3 to page1.i can aonly able to maintain 1 level.

Now i am thinking for a generic kind of implementation which i can easily implement on my next project.Please help me with your idea about this...

I am working on ASP.NET MVC.

A: 

It also gets complicated if you recall that not all page requests are GET bit include some POST and possibly other verbs.

I once wanted to do something similar but then abandoned the idea. It's not really that needed. As an idea on how to approach the problem...

At each request record the current page and the verb together in pair like:

GET /users
GET /users/add-user
POST /users/add-user
GET /users

You can store this information in the TempData collection, read it at each request and update it by adding current request details. Then you implement some framework method that will scan the collection skipping all POSTs (or whatever you need) and give you the previous GET url.

Developer Art