Full URL from relative Path - Suggestions / Corrections to a function
- From: tommaso.gastaldi@xxxxxxxxxxx
- Date: 16 Aug 2006 11:20:37 -0700
Hi friends
I was in the need to find a "definitive" :) solution to transform a
relative path
such as "~/MyDir/MyFile in a full web address. In particular I needed
it within
web services.
I would like to be informed that the framework provides a function to
do that, but for know I am missing it.
After some search on the groups, I have assembled the following
function, which would *seem* to work, but I would like to hear your
possible corrections / improvements / flaws / etc.
Thanks for any feedback
Tom
'---------------------------
Function FullUrlFromRelativePath(ByVal RelativePath As String) As
String
With HttpContext.Current.Request
Dim Port As String = .ServerVariables("SERVER_PORT")
If (Port Is Nothing OrElse Port = "80" OrElse Port = "443")
Then
Port = ""
Else
Port = ":" & Port
End If
Dim Protocol As String =
..ServerVariables("SERVER_PORT_SECURE")
If (Protocol Is Nothing OrElse Protocol = "0") Then
Protocol = "http://"
Else
Protocol = "https://"
End If
Dim ServerUrl As String = Protocol &
..ServerVariables("SERVER_NAME") & Port
Dim LocalPath As String
If RelativePath.TrimStart(" ").StartsWith("~") Then
LocalPath = .ApplicationPath &
RelativePath.Substring(1)
Else
LocalPath = RelativePath
End If
Return ServerUrl & LocalPath
End With
End Function
PS
I am also in doubt if the 443 should be considered only for secure
conns ...
.
- Prev by Date: Re: Preventing button code being run twice
- Next by Date: Re: Active Directory
- Previous by thread: Preventing button code being run twice
- Next by thread: VB 2005 Email Programming
- Index(es):
Relevant Pages
|