Products

Solutions

Resources

Partners

Community

About

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/20/2007 5:14 PM
 

Nope - no reply showed up, but my new post did.  Sorry to bother you.  (That was weird...)


Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
11/20/2007 9:11 PM
 

I recall looking through all the DNN common methods in the past to find one that takes a host relative url and generates an absolute url including the protocol and host. Not finding one I wrote the following function that I keep in my own class of common methods:

Public Function AddHost(ByVal URL As String) As String
    Dim result As String
    Dim host As String = HttpContext.Current.Request.ServerVariables("HTTP_HOST").TrimEnd("/"c)

    If URL.ToLower.Contains(host.ToLower) Then
        result = URL
    Else
        If Not URL.StartsWith("/") Then URL = "/" & URL
        result = host & URL
    End If
    Return DotNetNuke.Common.Globals.AddHTTP(result)
End Function

In your case, the following should return the desired absolute url:

Dim url As String = AddHost(Common.Globals.LinkClick (strFileID, PortalSettings.ActiveTab.TabID, ModuleId))


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
11/20/2007 9:37 PM
 

Will,

I looked at the code for the LinkTracker control to figure this out....I'm not sure why I have to do it this way, but it does work.  Here is the pertinent code i ended up with

 

Private Function GetFieldURL(ByVal urlString As String) As String

 

 

Dim url As String = urlStringTry

 

If Not url.StartsWith("http") And Not url.StartsWith("mailto") Then

url = AddHTTP(Request.Url.Host)

 

End If

url += Common.Globals.LinkClick(urlString, PortalSettings.ActiveTab.TabID, ModuleId,

 

 

 

False)Return urlCatch exc As Exception 'Module failed to load

ProcessModuleLoadException(

 

Me, exc)End Try

 

Return ""

 

End Function

 
New Post
11/21/2007 9:30 AM
 

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.


Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
11/21/2007 9:57 AM
 

I hope core would provide one of the overloaded function of LinkClick which will give the Full Url

 
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