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
  • 177,207
  • 343
  • 852
  • 1,351

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
  • 994,864
  • 265
  • 3,241
  • 2,902
0

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

Community
  • 1
  • 1
Gregory A Beamer
  • 16,680
  • 3
  • 24
  • 30