Try it, I even added a scheme too, just in case you want https :)
EDIT: port added (thanks Alex) to be super-duper of the super future:
MyHiddenField.Value = string.Format(
"{0}://{1}{2}/thank_you.aspx",
Request.Url.Scheme,
Request.Url.Host,
Request.Url.IsDefaultPort ? string.Empty : ":" + Request.Url.Port);
EDIT: Another good suggestion from @MikeSmithDev by putting it in a function
public string GetUrlForPage(string page)
{
return MyHiddenField.Value = string.Format(
"{0}://{1}{2}/{3}",
Request.Url.Scheme,
Request.Url.Host,
Request.Url.IsDefaultPort ? string.Empty : ":" + Request.Url.Port,
page);
}
Then you can do:
MyHiddenField.Value = GetUrlForPage("thank_you.aspx");
source
share