views:

35

answers:

1

Very simple question but I am unable to find an answer, I have a MVC 2 app in C#

I have a ActionResult the accept's HTTP POST's

How do I find out the URl of any posts to my ActionResult.

Thanks,

+1  A: 

I think you're looking for:

HttpContext.Current.Request.Url

To ease testability you should look to abstract your use of HttpContext as it's a pain to mock. Try wrapping your access to it in a separate object you can inject.

Matt Lacey
Thanks a lot....
Csharper
I just went to implement your code (i marked it as an answer becuase I remembered I done somehting similar last week and i thought it would work) and VS 2010 is throwing me an error saying HttpContextBase dosn't contain a definition for current!? Any Ideas
Csharper
@simon where are you calling it from. Works in my code on VS2010 when called from obect injected in to controller constructor.
Matt Lacey
Sorry I just tried to stick it straight in the ActionResult just to get it to work. having checked the MSDN site I realise I will have to abstract it out like you said above.
Csharper
@simon or get it in the controller and pass to the ActionResult
Matt Lacey