Geeks With Blogs

News

Agha Usman Ahmed JILAWATAN
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.
 
Posted on Monday, October 27, 2008 5:17 PM | Back to top


Comments on this post: Exact Server URL

# re: Exact Server URL
Requesting Gravatar...
Nice effort to solve the problem... I request u keep in touch with me so that I can learn such type of issues.
Left by Farhan Farooqui on Oct 27, 2008 5:39 PM

# re: Exact Server URL
Requesting Gravatar...
Thanks Agha Usnam you are my favourite.
Left by Syed Safiullah Hussaini on Oct 27, 2008 5:40 PM

Your comment:
 (will show your gravatar)


Copyright © Agha Usman Ahmed | Powered by: GeeksWithBlogs.net