Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to get a complete URL to a file?How to get a complete URL to a file?
Previous
 
Next
New Post
11/28/2007 11:41 PM
 

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


sunblognuke v5 for dnn

Ultimate Blogging Module for DotNetNuke Platform
The professional provider of DotNetNuke support, skin design and custom module development.

 
New Post
12/2/2007 3:23 PM
 

 

This will return the complete DNN Server Path.


#Region "Utilities"

' Needed because DNN returns the Back Slash not the Forward Slash!

        Private Function ReplaceSlashes( ByVal sPath As String ) As String

            Dim sTemp As String = Replace( sPath, "\", "/" )

            Return sTemp

        End Function

#End Region

In your code:

Dim sPath As String = ReplaceSlashes( Server.MapPath("~/DesktopModules/" ) )

Enjoy

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to get a complete URL to a file?How to get a complete URL to a file?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out