0

right now i take the

 RequestContext 

and pass this into a UrlHelper like this:

UrlHelper u = new UrlHelper(context);
string hrSyncUrl = u.Action("Update", "Person");

but the issue is that this seems to return:

/Person/Update

instead of:

http://www.mysite.com/Person/Update

so, given a controller and and action name, how can i generate a FULL url from inside a controller?

the reason that i need this is that i am generating an email so i need the full url to put in the body of that email.

leora
  • 188,729
  • 360
  • 878
  • 1,366

2 Answers2

3

By using the proper overload:

string hrSyncUrl = u.Action("Update", "Person", null, "http");

And to avoid hardcoding the protocol you could fetch it from the request:

var protocol = context.HttpContext.Request.Url.Scheme;
string hrSyncUrl = u.Action("Update", "Person", null, protocol);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

see ASP.NET MVC create absolute url from c# code

Community
  • 1
  • 1
Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32