473,804 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue with threading?

This is a long-overdue item on my punch list that I haven't had much time to
address in the past. I'm trying to get it off my plate this week. ;o)

We have a home-grown CMS that works pretty well. One issue we have is that
whenever a page is saved in the CMS, we grab the info about the user that is
saving the page and save it along with the page (so we can track who has
changed what).

This works most of the time.

SOMEtimes, however, it grabs the information from another user that is
logged in. It seems as if my threads are crossing. I'm trying to figure out
what I've failed to do correctly in my code.

To grab the userinfo, we call our class from one of our pages:

SecureUsers.su_ strUser

The secureusers class:

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

Public Class SecureUsers
Public Shared su_strUser As String
...
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
InitializeCompo nent()
su_strUser =
Server.HtmlEnco de(Request.Cook ies("CMSUser")( "su_strUser "))
End Sub
End Class

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

My guess is that it's the 'public shared' declaration for the su_strUser
string and that this is being set GLOBALLY (vs. per session) whenever any
CMS user calls this class. As such, if two people happen to save a page at
the same time, the info crosses.

If that's the case, what should I be using? Is there where I need to use
properties vs. public variables?

-Darrel

--
=============== =============== =============== =============== =====
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA
May 23 '07 #1
7 1092
My guess is that it's the 'public shared' declaration for the su_strUser
string and that this is being set GLOBALLY (vs. per session) whenever any
CMS user calls this class. As such, if two people happen to save a page at
the same time, the info crosses.

If that's the case, what should I be using? Is there where I need to use
properties vs. public variables?
Your guess is correct. The answer depends on the rest of your architecture
really. Is it enough just to removed the shared and make it private?
May 23 '07 #2
Your guess is correct. The answer depends on the rest of your
architecture really. Is it enough just to removed the shared and make it
private?
If I make it private or not shared, I can't then access the value from
another page:

SecureUsers.su_ strUser.ToStrin g

-Darrel
May 23 '07 #3
If I make it private or not shared, I can't then access the value from
another page:
If you need to access it in another page then store it in the Session, then
remove from the Session once it has been used.
May 23 '07 #4
If you need to access it in another page then store it in the Session,
then remove from the Session once it has been used.
So...it sounds like the issue is that when a person logs into our system,
we're saving their info as a cookie. Instead of saving the info to a cookie,
we should save it to a session? That makes sense.

Now, a new catch: the reason we were saving it as a cookie is that our CMS
is actually 3 separate applications. Yes, less than ideal for many reasons,
and something we hope to resolve down the road. In the interim, is there any
way to share session info between the 3 apps or is that just plain
impossible given that they are three separate apps?

-Darrel
May 23 '07 #5
You can't easily share the Session values, what I'd do is store the info in
a database that all 3 can access.

"darrel" <no*****@nowher e.comwrote in message
news:O%******** *******@TK2MSFT NGP06.phx.gbl.. .
>If you need to access it in another page then store it in the Session,
then remove from the Session once it has been used.

So...it sounds like the issue is that when a person logs into our system,
we're saving their info as a cookie. Instead of saving the info to a
cookie, we should save it to a session? That makes sense.

Now, a new catch: the reason we were saving it as a cookie is that our CMS
is actually 3 separate applications. Yes, less than ideal for many
reasons, and something we hope to resolve down the road. In the interim,
is there any way to share session info between the 3 apps or is that just
plain impossible given that they are three separate apps?

-Darrel

May 23 '07 #6
You can't easily share the Session values, what I'd do is store the info
in a database that all 3 can access.
Right...but that kind of takes me back to square one. How does the app know
who the person is to look up their info in the db?

Maybe I should ask a broader question based on our current scenario:

- Our CMS is actually 3 .net application.
- We want people to log into any one of the three and be logged in to the
other 2.

Based on that, what would folks...
a) quick workaround hack solution to get the above working option be?
and
b) more appropriate, more secure option be (even if it includes a
rewrite).

At this point, for 'a', I'm thinking the easiest option is to do what we're
doing, but don't attempt to read the cookie from a class and just read it
directly from whichever page is trying to get the information (as they I can
use non-shared variables). The drawbacks is that this is entirely unsecure
as the login info is all sitting there in a cookie. Thats not too worrisome
for us, as this is an internal app for internal users, but probably not good
practice.

As for 'b', I'm thinking the solution would be to:

- bring the 3 apps together into one app
- store the permission credentials as a session variable

Am I on the right track there? With using the session variable, could I
still read them from a class and not have thread overlap?

-Darrel
May 23 '07 #7
Convert your usersession object into a hash table or namevalue collection.
Use the session id as the key, the value is the user info. To grab
information, you simply use the user's session which is guaranteed unique
and so there is no possibility of data corruption. This is not a
cross-threading issue by the way, it is simple data corruption.

As you know, there is no free cheese. So here is the cache. The size of the
namevalue collection grows unbounded. You will need some sort of cleanup
routine to purge the collection ever so often. In the past, I have used a
global timer to purge the information. How do you know if the information
can be purged? One simple method is to time stamp the last collection
lookup. If it is older than some value, remove it from the collection. I'd
suggest you provider a wrapper class that encapsulates all this logic in one
place.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"darrel" <no*****@nowher e.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>You can't easily share the Session values, what I'd do is store the info
in a database that all 3 can access.

Right...but that kind of takes me back to square one. How does the app
know who the person is to look up their info in the db?

Maybe I should ask a broader question based on our current scenario:

- Our CMS is actually 3 .net application.
- We want people to log into any one of the three and be logged in to the
other 2.

Based on that, what would folks...
a) quick workaround hack solution to get the above working option be?
and
b) more appropriate, more secure option be (even if it includes a
rewrite).

At this point, for 'a', I'm thinking the easiest option is to do what
we're doing, but don't attempt to read the cookie from a class and just
read it directly from whichever page is trying to get the information (as
they I can use non-shared variables). The drawbacks is that this is
entirely unsecure as the login info is all sitting there in a cookie.
Thats not too worrisome for us, as this is an internal app for internal
users, but probably not good practice.

As for 'b', I'm thinking the solution would be to:

- bring the 3 apps together into one app
- store the permission credentials as a session variable

Am I on the right track there? With using the session variable, could I
still read them from a class and not have thread overlap?

-Darrel

May 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1456
by: Zuel | last post by:
Sup everyone! I wrote this code for Tomcat appserver but I am told from an associate that it has threading issues. The basic idea is to store a read only data table for everyone to use. It takes some time for the table to be created. I want to store the table in a singleton and update it periodicly, basicaly when a user logs into the system. By keeping 1 table allocated I don't have to worry about memmory usage and if a user does...
9
1793
by: Sam Loveridge | last post by:
Hi all. I'm relatively new to delegates and asynchronous threading and am running into an issue. I need to asynchronously call a method (which I'm doing with a delegate and BeginInvoke) and from the callback method, or at some point after the EndInvoke has been called to end the asynchronous operation I need to asynchronously call a different method. I really want to keep this event based and use delegates and callbacks rather than loop...
2
2362
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If mUIO_Threads(i) Is Nothing Then mUIO_Threads(i) = New System.Threading.Thread(AddressOf mUIO_DAQ(i).InitDAQ) mUIO_Threads(i).Name = mUIO_DAQ(i).UIO_IPAddr mUIO_Threads(i).IsBackground = False
9
271
by: Sam Loveridge | last post by:
Hi all. I'm relatively new to delegates and asynchronous threading and am running into an issue. I need to asynchronously call a method (which I'm doing with a delegate and BeginInvoke) and from the callback method, or at some point after the EndInvoke has been called to end the asynchronous operation I need to asynchronously call a different method. I really want to keep this event based and use delegates and callbacks rather than loop...
2
1835
by: =?Utf-8?B?TWljaGFlbCBNYWVz?= | last post by:
Hello, I have an Mdi-application which also is a remoting-server (Ipc). Several instances can co-exist on the same machine. I have a small app (search-engine) (remoting-client) which calls a sub on the MDI (specific instance) thus retrieving eg the data of a certain customer. If the customer childform is already instanciated, there is no problem. If the destination-childform is not yet open, it will be opened like this:
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.