I have an ascx control which contains in markup:
<a href="<%# GetName() %>">
In the ascx.cs codebehind file I have the following:
protected string GetName() {
return HttpContext.Current.Request.ServerVariables["HTTP_HOST"];
}
In codebehind there's also a handler for a button, that calls this method:
protected void myButtonClick(object sender, EventArgs e)
{
string server = GetName();
...
}
When I request the page containing the control like https://my.site.com/test.aspx, the page shows me the external name (my.site.com), but when I hit the button the call in the handler in codebehind gets the internal name (my123.test.local).
Can anybody explain to me why there's a difference? And how I can get the external domain part in codebehind?
p.s. SERVER_NAME and HTTP_HOST give both the same result.
Also, when I access a page from the internet (https://my.site.com/test.aspx) containing something like:
Response.Write("SERVER_NAME 1: " + Request["SERVER_NAME"]);
Response.Write("SERVER_NAME 2: " + HttpContext.Current.Request.ServerVariables["SERVER_NAME"]);
the first line shows the internal name and the second line shows the external address, like:
SERVER_NAME 1: my123.test.local
SERVER_NAME 2: my.site.com