M
MattB
Just in case anyone else wants to do this, here's a shared function I used
to switch into the https protocol. Pretty simple, and I'm sure it won't be
able to handle every scenario but it's a start. Hope it helps someone. It's
come in handy for me!
To use, put in a vb class and call with the name of the page you want to
load as https like this:
myClass.GetRelSecLnk(myPage.aspx) it will return something like
https://myApp/myPage.aspx
Public Shared Function GetRelSecLnk(ByVal RLink As String)
'Returns a https link from a relative link (genearlly assuming the same
folder level or lower)
Dim coll As System.Collections.Specialized.NameValueCollection
Dim strHost As String, strScript As String, strScriptPath As String, strURL
As String, i As Int16
' Load ServerVariable collection into NameValueCollection object.
coll = System.Web.HttpContext.Current.Request.ServerVariables()
strHost = coll.Item("HTTP_HOST") 'host name from http request of calling
page
strScript = coll.Item("SCRIPT_NAME") 'script/page name, which may have dirs:
mydir/mypage.aspx
'chop off the page name (it will be of the calling page anyway)
Dim aTmp As Array = strScript.Split("/")
If aTmp.GetUpperBound(0) > 1 Then
For i = 0 To aTmp.GetUpperBound(0) - 1
strScriptPath = strScriptPath & aTmp(i) & "/"
Next
End If
'reassemble a secure URL appending the relative link passed in
strURL = "https://" & strHost & strScriptPath & RLink
Return (strURL)
End Function
to switch into the https protocol. Pretty simple, and I'm sure it won't be
able to handle every scenario but it's a start. Hope it helps someone. It's
come in handy for me!
To use, put in a vb class and call with the name of the page you want to
load as https like this:
myClass.GetRelSecLnk(myPage.aspx) it will return something like
https://myApp/myPage.aspx
Public Shared Function GetRelSecLnk(ByVal RLink As String)
'Returns a https link from a relative link (genearlly assuming the same
folder level or lower)
Dim coll As System.Collections.Specialized.NameValueCollection
Dim strHost As String, strScript As String, strScriptPath As String, strURL
As String, i As Int16
' Load ServerVariable collection into NameValueCollection object.
coll = System.Web.HttpContext.Current.Request.ServerVariables()
strHost = coll.Item("HTTP_HOST") 'host name from http request of calling
page
strScript = coll.Item("SCRIPT_NAME") 'script/page name, which may have dirs:
mydir/mypage.aspx
'chop off the page name (it will be of the calling page anyway)
Dim aTmp As Array = strScript.Split("/")
If aTmp.GetUpperBound(0) > 1 Then
For i = 0 To aTmp.GetUpperBound(0) - 1
strScriptPath = strScriptPath & aTmp(i) & "/"
Next
End If
'reassemble a secure URL appending the relative link passed in
strURL = "https://" & strHost & strScriptPath & RLink
Return (strURL)
End Function