1

I have a ASP.NET MVC project in which I have a method on a controller which is being called from two separate pages, until now the behaviour was the same but now I need it to be slightly different I just need to see if I'm on page A or page B so I know which behaviour happens.

Is there any solution with the ViewData or View or something else with which I can check from which page this method was called?

tereško
  • 58,060
  • 25
  • 98
  • 150
George Bora
  • 1,618
  • 6
  • 26
  • 45
  • 4
    Would it not be easier to pass a control variable indicating page 1/2 or functionality 1,2,3.. etc to this controller method ? – Ravi Y Mar 04 '13 at 10:36
  • I thought of that but I'm a bit wary because I'm not supposed to change page A or B, not even to change the query string or etc so I was hoping there was something which can be done only on the method side. – George Bora Mar 04 '13 at 10:38
  • Got it. Check if this previous SO answer can help you : http://stackoverflow.com/questions/1529265/asp-net-mvc-finding-out-the-caller-to-a-method-when-modelstate-isvalid – Ravi Y Mar 04 '13 at 10:40
  • 1
    HttpContext.Request.Url may provide you the source path – helloworld Mar 04 '13 at 10:44
  • 1
    Check this answer - use Request.UrlReferrer http://stackoverflow.com/questions/1471188/how-do-i-get-the-referrer-url-in-an-asp-net-mvc-action – Luke Baughan Mar 04 '13 at 10:56
  • Could you guys please convert your comments to question so I can upvote them and mark one as the correct answer, actually both `HttpContext.Request.Url` and `Request.UrlRefferer` work. – George Bora Mar 04 '13 at 11:51

0 Answers0