hismightiness wrote
Okay... This is now VERY weird. Your post WAS there, but I didn't see it until this morning. [insert picture of monkey scratching his head here]
Now that I am able to get into my IDE, I can see that I have done something similar to Bill. Since my example would contain too much BL, I will expand on Bill's example some:
Public Function AddHost(ByVal URL As String) As String
' I added the use of String.Concat - this is MUCH faster on a high traffic site
' just in case a stateless thread calls this method (it could happen)
If HttpContext.Current Is Nothing Then
Return URL
End If
Dim result As String
'Dim host As String = HttpContext.Current.Request.ServerVariables("HTTP_HOST").TrimEnd("/"c)
' I usually use SERVER_NAME and haven't run into any problems yet
Dim host As String = HttpContext.Current.Request.ServerVariables("SERVER_NAME")
If URL.ToLower.Contains(host.ToLower) Then
result = URL
Else
If Not URL.StartsWith("/") Then URL = String.Concat("/", URL)
result = String.Concat(host, URL)
End If
Return DotNetNuke.Common.Globals.AddHTTP(result)
End Function
I haven't looked at it yet, but I assume that the DNN AddHTTP method determines whether the request is SSL or not. Like this:
Dim strHttp As String = String.Empty
If String.Equals(HttpContext.Current.Request.ServerVariables("HTTPS"), "ON") Then
strHttp = "https://"
Else
strHttp = "http://"
End If
Paul, your example looks fine, as long as it does what you need it to. I think these other two examples might be a bit more generic for your needs.
I had converted your method to my Uitlity class. But as your assumation, it do not work well if the live webiste including the ip port munber such as http://124.24.67.1:2022/yourwebsite/ your method will just get the url http://124.24.67.1/yourwebsite/ , not the correct url http://124.24.67.1:2022/yourwebsite/ . So I recommend to change the method original as follows:
''' <summary>
''' Get the complete url to a file
''' </summary>
''' <param name="URL">the url to be resolved ( such as modulepath )</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function AddHost(ByVal URL As String) As String
' just in case a stateless thread calls this method (it could happen)
If HttpContext.Current Is Nothing Then
Return URL
End If
Dim result As String
Dim host As String = HttpContext.Current.Request.ServerVariables("HTTP_HOST").TrimEnd("/"c)
'Dim host As String = HttpContext.Current.Request.ServerVariables("SERVER_NAME")
If URL.ToLower.Contains(host.ToLower) Then
result = URL
Else
'String.Concat - this is MUCH faster on a high traffic site
If Not URL.StartsWith("/") Then URL = String.Concat("/", URL)
result = String.Concat(host, URL)
End If
Return DotNetNuke.Common.Globals.AddHTTP(result)
End Function