Generate the "server" address of your action and then append the query string:
return string.Format(Url.Action("RegisterConfirmation", "Account")+"?Id={0}", confirmationToken);
or:
return string.Format(Url.Action("RegisterConfirmation", "Account", new {Id = confirmationToken });
and if you need a full absolute url, you can use this third version:
return string.Format(Url.Action("RegisterConfirmation", "Account", new {Id = confirmationToken }, Request.Url.Scheme);
If you need to generate the full url outside one of your controllers, use HttpContext.Current.Request.Url.Scheme
instead of Request.Url.Scheme
. In order to take advantage from Url.Action
, if you call your CreateUserConfirmationLink
method from one of your controllers (which I assume you do), you could modify the method to take the UrlHelper as input parameter:
private string CreateUserConfirmationLink(string confirmationToken, UrlHelper urlHelper)
{
return string.Format(urlHelper.Action("RegisterConfirmation", "Account", new {Id = confirmationToken }, HttpContext.Current.Request.Url.Scheme);
}
Edit: for .Net 4 and above, the UrlHelper can be instantiated from the current context:
private string CreateUserConfirmationLink(string confirmationToken)
{
UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
return string.Format(urlHelper.Action("RegisterConfirmation", "Account", new {Id = confirmationToken }, HttpContext.Current.Request.Url.Scheme);
}