I heard couple of requirement like this especially after VS 2005, in which you have development server with the dynamic port which change most of the time when you start Visual Studio.
The problem is how to get the SERVER URL with port number. Here is the code in vb.net
Public Shared Function GetServerUrl(ByVal req As System.Web.HttpRequest) As String
Dim port As String = req.ServerVariables("SERVER_PORT")
Dim AppPath As String = req.ApplicationPath
Dim reurnUrl As String = "http://" + req.Url.Host
If port <> "" And port <> "80" Then
reurnUrl += ":" + port
End If
If AppPath <> "/" Then
reurnUrl += AppPath
End If
Return reurnUrl
End Function
Just pass the request object from any asp.net page and you will get the exact server URL, It is best when you are generating links in dynamic email content.