473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What's wrong with this code?

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
2 957
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
65
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.