switching to https solution

  • Thread starter Thread starter MattB
  • Start date Start date
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
 
Hi Matt,

From my experience using Shared I can tell you that it is viewable by
everyone... Meaning that if I click on a a button calling a shared function
and someone else using a different pc were to click on the button at the
same time then whatever I set in button event will be viewed by the other
user...

Yama
 
Well that's no good. What should I use instead? I made it shared to make the
function available to all pages in the solution. What could give me that but
still have seperate instances created for each call?
 
Create a public class, with public method in it. Reference the assembly in
the pages that need it. Create an instance of it when needed, and use the
instance.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Well when I discovered that everything Shared I had in my n-Tier was actually viewable by all I decided to take them off and use an instance of it!

For instance:
Namespace AFC.Portal
Public Class myClass
Public Shared Function() As System.Int32
Private _i As System.Int32
Friend Property i() As System.Int32
Get
Return _i
End Get
Set(ByVal Value As System.Int32)
_i = Value
End Set
End Property
End Function
End Class
End Namespace

Now the cool thing is that this i variable is easily accessible in all my web page as in:

default.aspx.vb (code behind of my default.aspx page)

Imports AFC.Portal.myClass
Namespace AFC.Portal
Public Class CDefault Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(Cstr(i+1))
End Sub
End Class
End Namespace

Now if you try to open ten different browser it would mimic ten different users viewing you web page. You will see that each page will have a different value displayed for the varaible i !!!

I fixed this as:

Namespace AFC.Portal
Public Class myClass
Public Function() As System.Int32
Private _i As System.Int32
Friend Property i() As System.Int32
Get
Return _i
End Get
Set(ByVal Value As System.Int32)
_i = Value
End Set
End Property
End Function
End Class
End Namespace

default.aspx.vb (code behind of my default.aspx page)

'-- // Imports AFC.Portal.myClass
Namespace AFC.Portal
Public Class CDefault Inherits System.Web.UI.Page
Private myInteger As New myClass

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(CStr(myInteger.i +1))
End Sub
End Class
End Namespace

Hope this helped...

Yama
 
Oooppsss wrote some bad code here is the correct version:

Namespace AFC.Portal
Public Class myClass
Private Shared _i As System.Int32
Friend Shared Property i() As System.Int32
Get
Return _i
End Get
Set(ByVal Value As System.Int32)
_i = Value
End Set
End Property
End Function
End Namespace
Well when I discovered that everything Shared I had in my n-Tier was actually viewable by all I decided to take them off and use an instance of it!

For instance:
Namespace AFC.Portal
Public Class myClass
Public Shared Function() As System.Int32
Private _i As System.Int32
Friend Property i() As System.Int32
Get
Return _i
End Get
Set(ByVal Value As System.Int32)
_i = Value
End Set
End Property
End Function
End Class
End Namespace

Now the cool thing is that this i variable is easily accessible in all my web page as in:

default.aspx.vb (code behind of my default.aspx page)

Imports AFC.Portal.myClass
Namespace AFC.Portal
Public Class CDefault Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(Cstr(i+1))
End Sub
End Class
End Namespace

Now if you try to open ten different browser it would mimic ten different users viewing you web page. You will see that each page will have a different value displayed for the varaible i !!!

I fixed this as:

Namespace AFC.Portal
Public Class myClass
Public Function() As System.Int32
Private _i As System.Int32
Friend Property i() As System.Int32
Get
Return _i
End Get
Set(ByVal Value As System.Int32)
_i = Value
End Set
End Property
End Function
End Class
End Namespace

default.aspx.vb (code behind of my default.aspx page)

'-- // Imports AFC.Portal.myClass
Namespace AFC.Portal
Public Class CDefault Inherits System.Web.UI.Page
Private myInteger As New myClass

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(CStr(myInteger.i +1))
End Sub
End Class
End Namespace

Hope this helped...

Yama
 
Thanks. So just to clarify, I'd do that in my page (for the example I gave
earlier) like this?:

Dim myClass1 as new Myclass

......

strX = MyClass1.GetRelSecLnk("myPage.aspx")

Thanks!
 
You got it, Matt!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top