views:

420

answers:

2

Hi,

What's the correct way to get the full url (including protocol and domain) for a controller and action? I need this to be able to send links to pages via email.

I was hoping to just use Url.Action() and concatenate it onto the current server hostname from Request.Url. However, it seems that Url.Action is context sensitive and so will not show the full path if you are already within the same controller.

Any ideas?

Thanks

James

A: 

I think

HttpContext.Current.Request.RawUrl;

will do the trick. Read more...

Tomas Lycken
+3  A: 

There are overloads of Url.Action() that take the hostname, protocol, etc. Calling one of these overloads will generate a fully-qualified URL suitable for emailing.

Levi
Excellent, thanks for the quick response
James