Relative paths IFRAME

Last post 09-28-2003 1:37 AM by jmatthewsr. 5 replies.

Sort Posts:

  • Relative paths IFRAME

    09-19-2003, 4:46 PM
    • Member
      85 point Member
    • jmatthewsr
    • Member since 09-10-2003, 7:29 PM
    • Posts 17
    I have setup DNN as a portal for an internal website. By internal I mean, NAT'd 192.168.x.x addresses that are not visible to the outside world. I also have it setup so that users can reach the internal site from the outside world via a virtual directory that is secured via SSL. ie: https://mycompany.com/dnn

    The problem I am running into is that if I use the IFRAME control and specify a URL to a local directory, ie "www.mycompany.com/mydir", the internal users see it fine but from the outside world the IFAME control is trying to read http://www.mycompany.com/mydir, which does not work for the following reasons:
    * obviously the outside world has to access the dnn site using httpS://
    * the outside world also has to access the site via the virtual directory: https://www.mycompany.com/dnn/mydir

    What would be the recommend way to give access to the outside world via SSL and keep the IFRAMe module happy? I was thinking some kind of relative path, I tried using "~", but this did not work.

    Thanks,

    -Justin
  • Re: Relative paths IFRAME

    09-19-2003, 5:14 PM
    • Star
      13,648 point Star
    • cathal
    • Member since 06-18-2002, 4:02 PM
    • Belfast, Northern Ireland
    • Posts 2,702
    • TrustedFriends-MVPs
    The IFRAME module loads a brand new page into the current page, but does not check to see the current page context. The code that does this exists in DesktopModules\IFrame\IFrame.ascx.vb and looks like this:

    lblIFrame.Text = "<iframe frameborder=""" & strBorder & """ src=""" & IIf(InStr(1, strSrc, "://") = 0, "http://", "") & strSrc & """ height=""" & strHeight & """ width=""" & strWidth & """ scrolling=""" & strScrolling & """>Your Browser Does Not Support Frames</iframe>"

    note the http protocal. If your site is totally HTTPS i.e. SSL, simply change this to HTTPS, otherwise use HttpWebRequest.ProtocolVersion from the system.net namespace to detect the current protocol, so you can write it dynamically.

    Cathal
  • Re: Relative paths IFRAME

    09-19-2003, 5:20 PM
    • Member
      85 point Member
    • jmatthewsr
    • Member since 09-10-2003, 7:29 PM
    • Posts 17
    Ok, fixing the HTTP(s) request seems reasonable, any idea how I could make the IFRAME work with relative paths? I still have this issue even after fixing the URL request. Really the IFRAME somehow would need to be configured with a URL of "~/mydir", so when internal users access the IFRAME it would point to http://www.mycompany.com/mydir and when external users access the site it points to: https://www.mycompany.com/dnn/mydir.

    Thanks!

    -Justin
  • Re: Relative paths IFRAME

    09-19-2003, 6:02 PM
    • Star
      13,648 point Star
    • cathal
    • Member since 06-18-2002, 4:02 PM
    • Belfast, Northern Ireland
    • Posts 2,702
    • TrustedFriends-MVPs
    You could make a custom modification to render the path based on the current request i.e. in the iframe section, you only type "~mypage.asp". In the IFrame.ascx.vb you could check for requests that begin with ~, and replace it with the path (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttprequestclasspathtopic.asp ), followed by the rest of the string. This should allow you to use both local and remote pages.

    Cathal
  • Re: Relative paths IFRAME

    09-26-2003, 2:23 AM
    • Member
      85 point Member
    • jmatthewsr
    • Member since 09-10-2003, 7:29 PM
    • Posts 17
    Here is my modification for the relative paths, being a newbie to vb and .net it took longer than I thought so hopefully this will help others, and eventually make its way into the dnn distribution. Also, please let me know if there is anything wrong here. Thanks.
    ----------------
    ' mod for correctly resolving http or https requests
    ' and resolving relative paths using the ~ character before the IFRAME URL

    Dim strServer As String = CType(Request.ServerVariables("SERVER_NAME"), String)
    Dim strPort As String = CType(Request.ServerVariables("SERVER_PORT"), String)
    Dim strHttps As String = CType(Request.ServerVariables("HTTPS"), String)

    Dim strUrlBegin As String

    strUrlBegin = IIf(strHttps = "off", "http://", "https://")

    strSrc.TrimStart(" "c) 'trim leading whitespace

    If (strSrc.Substring(0, 1) = "~") Then

    strPort = IIf(strPort = "80", "", String.Concat(":", strPort))

    strSrc = strSrc.TrimStart("~"c, "/"c)
    strSrc = String.Concat(strServer, strPort, "/", Request.ApplicationPath.TrimStart("/"c), "/", strSrc)
    End If

    If strSrc <> "" Then
    lblIFrame.Text = "<iframe frameborder=""" & strBorder & """ src=""" & IIf(InStr(1, strSrc, "://") = 0, strUrlBegin, "") & strSrc & """ height=""" & strHeight & """ width=""" & strWidth & """ title=""" & strTitle & """ scrolling=""" & strScrolling & """>Your Browser Does Not Support Frames</iframe>"
    End If

    --------------
  • Re: Relative paths IFRAME

    09-27-2003, 11:31 PM
    • Member
      85 point Member
    • jmatthewsr
    • Member since 09-10-2003, 7:29 PM
    • Posts 17
    My previous post has a major bug that causes an exception. Here is the fixed code:
    ------------------------------
    ' mod for correctly resolving http or https requests
    ' and resolving relative paths using the ~ character before the IFRAME URI

    If (strSrc = Nothing) Then
    Return
    End If

    Dim strServer As String = CType(Request.ServerVariables("SERVER_NAME"), String)
    Dim strPort As String = CType(Request.ServerVariables("SERVER_PORT"), String)
    Dim strHttps As String = CType(Request.ServerVariables("HTTPS"), String)

    Dim strUrlBegin As String

    strUrlBegin = IIf(strHttps = "off", "http://", "https://")

    strSrc.TrimStart(" "c) 'trim leading whitespace

    If (strSrc.Length < 1) Then
    Return
    End If

    If (strSrc.Substring(0, 1) = "~") Then

    strPort = IIf(strPort = "80", "", String.Concat(":", strPort))

    strSrc = strSrc.TrimStart("~"c, "/"c)
    strSrc = String.Concat(strServer, strPort, "/", Request.ApplicationPath.TrimStart("/"c), "/", strSrc)
    End If

    If strSrc <> "" Then
    lblIFrame.Text = "<iframe frameborder=""" & strBorder & """ src=""" & IIf(InStr(1, strSrc, "://") = 0, strUrlBegin, "") & strSrc & """ height=""" & strHeight & """ width=""" & strWidth & """ title=""" & strTitle & """ scrolling=""" & strScrolling & """>Your Browser Does Not Support Frames</iframe>"
    End If
    -------------------------------
Page 1 of 1 (6 items)