Full URL from relative Path - Suggestions / Corrections to a function

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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 ...

.



Relevant Pages

  • Re: SSHD revelaing too much information.
    ... >>'OpenSSH_2.3.0' part is required for the protocol. ... Displaying the extra version string info later on would be pointless, ... Bragging might attract the wrong types to test ... with "unsubscribe freebsd-security" in the body of the message ...
    (FreeBSD-Security)
  • Re: Zero terminated strings
    ... including when you do things like string concatenation etc ... Simple "tricks" are all you need to implement a decent link level ... <snip basic link layer protocol> ...
    (comp.lang.c)
  • Re: How does one unit test a Mail Session?
    ... public class SessionAdapter implements MySession { ... public void setProtocolForAddress(String addresstype, String protocol){ ...
    (comp.lang.java.programmer)
  • Re: how to read AIS data from encapsulated NMEA VDO sentence
    ... The data is actually send as a bitstream and the protocol for every ... perhaps 16 bit bytes) as a character. ... one character in the string given above. ... capture buffer to read each character out in ascii values, ...
    (rec.boats.electronics)