By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,619 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,619 IT Pros & Developers. It's quick & easy.

What's wrong with this code?

P: n/a
Our CMS sets a cookie when you login. Various applications within the CMS
check the cookie to establish the user's name, permissions, etc.

The class below is what is references whenever we need to grab the user
data. For instance, when the user saves a database record, we attach their
username to the record by requesting SecureUsers.su_strUser

The problem (as you can probably guess) is that if two people trigger a
thread at the same time, one user's data can be 'grabbed' by the other's
process.

I'm assume this is because these variables are all 'shared', as 'shared' is
at the class level rather than instance level, correct? If so, are Public
Properties the solution? Or should I be calling a public function within
this class that returns the values (creating an instance of the class
first)? Or...?

-Darrel

================================================== ===============

Public Class SecureUsers
Inherits System.Web.UI.UserControl

Public Shared su_strUser As String
Public Shared su_strEmail As String
Public Shared su_intDistrict As Integer
Public Shared su_intAdminLevel As Integer
Public Shared su_categories As String
Public Shared su_strDistrict As String

....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Request.Cookies("CMSUser") Is Nothing Then
su_strUser =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_s trUser"))
su_strDistrict =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_s trDistrict"))
su_intDistrict =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_i ntDistrict"))
su_strEmail =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_s trEmail"))
su_categories =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_c ategories"))
su_intAdminLevel =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_i ntAdminLevel"))
End If
End Sub

End Class

================================================== ===============
Jan 30 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you are correct, in vb shared means share at class level. just remove
the shared attribute.

-- bruce (sqlwork.com)

darrel wrote:
Our CMS sets a cookie when you login. Various applications within the CMS
check the cookie to establish the user's name, permissions, etc.

The class below is what is references whenever we need to grab the user
data. For instance, when the user saves a database record, we attach their
username to the record by requesting SecureUsers.su_strUser

The problem (as you can probably guess) is that if two people trigger a
thread at the same time, one user's data can be 'grabbed' by the other's
process.

I'm assume this is because these variables are all 'shared', as 'shared' is
at the class level rather than instance level, correct? If so, are Public
Properties the solution? Or should I be calling a public function within
this class that returns the values (creating an instance of the class
first)? Or...?

-Darrel

================================================== ===============

Public Class SecureUsers
Inherits System.Web.UI.UserControl

Public Shared su_strUser As String
Public Shared su_strEmail As String
Public Shared su_intDistrict As Integer
Public Shared su_intAdminLevel As Integer
Public Shared su_categories As String
Public Shared su_strDistrict As String

...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Request.Cookies("CMSUser") Is Nothing Then
su_strUser =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_s trUser"))
su_strDistrict =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_s trDistrict"))
su_intDistrict =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_i ntDistrict"))
su_strEmail =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_s trEmail"))
su_categories =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_c ategories"))
su_intAdminLevel =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_i ntAdminLevel"))
End If
End Sub

End Class

================================================== ===============

Jan 30 '07 #2

P: n/a
you are correct, in vb shared means share at class level. just remove the
shared attribute.
So, is this the proper syntax?:

class MyClass
public MyVariable

and than retrieve it via:

dim MyInstanceOfMyClass as new MyClass
dim localVariable = MyInstanceOfMyClass.MyVariable

-Darrel
Jan 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.