VERY IMPORTANT: Sharing

G

Guest

Hello All

I have developed a new site using ASP.NET/VB.NET. I fell into a big problem. Here is the problem

I created a module as follow

Namespace FinancialCompany.Porta
Public Class myPropertie
Private _intCounter As System.Int3

Public Property intCounter() As System.Int3
Ge
Return _intCounter
End Ge
Set(ByVal Value As System.Int32
_intCounter = Valu
End Se
End Propert
End Class
End Namespac

Now I use this in an ASP.NET page as follow

Imports FinancialCompany.Portal.myPropertie

Namespace FinancialCompany.Porta
Public Class _defaul
Inherits System.Web.UI.Pag

Private m_test As System.Int32 = Resquest.QueryString("TEST"

Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter +=

Response.Write("Here is the result: " + CStr(m_test)
End If
End Sub
End Clas
End Namespac

Now when I tested this with two to five users with the following URLs

User 1: http://localhost/myproject/default.aspx?TEST=
User 2: http://localhost/myproject/default.aspx?TEST=
User 3: http://localhost/myproject/default.aspx?TEST=

If user 2 clicks the URL he gets
Here is the result:

But if user 3 cllicks the URL he gets
Here is the result:
instead of
Here is the result:

Hence the intCount property remains active for every users!!! I expect it to be a different instance for each different users

How come is it being shared??

I am using Windows 2000 Server, ASP.NET 2003, & Framework 1.

Hope someone can help me... Should I simply just use Session("intCount") instead or even Application("intCounter")

I really need to understand why the hack is intCounter being stored in memory...

Thanks

Yam
 
K

Ken Cox [Microsoft MVP]

Not sure this is your problem, but I noticed a typo:

Private m_test As System.Int32 = Resquest.QueryString("TEST")

Should be Request
 
G

Guest

Hi Ken

Thanks for correcting the typo. I typed an demo program to present my case... :) Sorry for the typo

The bug is that two different user can share the same session. So for instance
--- if I am userA on computer
--- and you are userB on computer
--- if userA is viewing ReportA
--- then userB although trying to view ReportB will see ReportA...

I have report name as a string property called strReportName that keeps track (kinda like a session variable) of the report name. But when userA selects the report userB will share that report name..

Hopefully that is a little more self-explanatory

Yama Kamya


----- Ken Cox [Microsoft MVP] wrote: ----

Not sure this is your problem, but I noticed a typo

Private m_test As System.Int32 = Resquest.QueryString("TEST"

Should be Reques
 
G

Guest

Hi

Actually the component code should be

myModule.vb code
Namespace FinancialCompany.Porta
Public Module myModul
Public Class myPropertie
Private _intCounter As System.Int3

Public Property intCounter() As System.Int3
Ge
Return _intCounter
End Ge
Set(ByVal Value As System.Int32
_intCounter = Valu
End Se
End Propert
End Class
End Modul
End Namespac

default.aspx code
Imports FinancialCompany.Portal.myModule.myPropertie

Namespace FinancialCompany.Porta
Public Class _defaul
Inherits System.Web.UI.Pag

Private m_test As System.Int32 = Request.QueryString("TEST"

Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter +=

Response.Write("Here is the result: " + CStr(m_test)
End If
End Sub
End Clas
End Namespac


Yama Kamya

----- Yama wrote: ----

Hello All

I have developed a new site using ASP.NET/VB.NET. I fell into a big problem. Here is the problem

I created a module as follow

Namespace FinancialCompany.Porta
Public Class myPropertie
Private _intCounter As System.Int3

Public Property intCounter() As System.Int3
Ge
Return _intCounter
End Ge
Set(ByVal Value As System.Int32
_intCounter = Valu
End Se
End Propert
End Class
End Namespac


Now I use this in an ASP.NET page as follow

Imports FinancialCompany.Portal.myPropertie

Namespace FinancialCompany.Porta
Public Class _defaul
Inherits System.Web.UI.Pag

Private m_test As System.Int32 = Resquest.QueryString("TEST"

Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter +=

Response.Write("Here is the result: " + CStr(m_test)
End If
End Sub
End Clas
End Namespac

Now when I tested this with two to five users with the following URLs

User 1: http://localhost/myproject/default.aspx?TEST=
User 2: http://localhost/myproject/default.aspx?TEST=
User 3: http://localhost/myproject/default.aspx?TEST=

If user 2 clicks the URL he gets
Here is the result:

But if user 3 cllicks the URL he gets
Here is the result:
instead of
Here is the result:

Hence the intCount property remains active for every users!!! I expect it to be a different instance for each different users

How come is it being shared??

I am using Windows 2000 Server, ASP.NET 2003, & Framework 1.

Hope someone can help me... Should I simply just use Session("intCount") instead or even Application("intCounter")

I really need to understand why the hack is intCounter being stored in memory...

Thanks

Yam
 
V

vMike

Maybe this will help.
Modules are a reference type similar to classes, but with some important
distinctions. The members of a module are implicitly Shared and scoped to
the declaration space of the standard module's containing namespace, rather
than just to the module itself. Unlike classes, modules can never be
instantiated, do not support inheritance, and cannot implement interfaces.



Hi,

Actually the component code should be:

myModule.vb code:
Namespace FinancialCompany.Portal
Public Module myModule
Public Class myProperties
Private _intCounter As System.Int32

Public Property intCounter() As System.Int32
Get
Return _intCounter
End Get
Set(ByVal Value As System.Int32)
_intCounter = Value
End Set
End Property
End Classs
End Module
End Namespace

default.aspx code:
Imports FinancialCompany.Portal.myModule.myProperties

Namespace FinancialCompany.Portal
Public Class _default
Inherits System.Web.UI.Page

Private m_test As System.Int32 = Request.QueryString("TEST")

Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter += 2

Response.Write("Here is the result: " + CStr(m_test))
End If
End Sub
End Class
End Namespace


Yama Kamyar

----- Yama wrote: -----

Hello All,

I have developed a new site using ASP.NET/VB.NET. I fell into a big problem. Here is the problem:

I created a module as follow:

Namespace FinancialCompany.Portal
Public Class myProperties
Private _intCounter As System.Int32

Public Property intCounter() As System.Int32
Get
Return _intCounter
End Get
Set(ByVal Value As System.Int32)
_intCounter = Value
End Set
End Property
End Classs
End Namespace


Now I use this in an ASP.NET page as follow:

Imports FinancialCompany.Portal.myProperties

Namespace FinancialCompany.Portal
Public Class _default
Inherits System.Web.UI.Page

Private m_test As System.Int32 = Resquest.QueryString("TEST")

Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter += 2

Response.Write("Here is the result: " + CStr(m_test))
End If
End Sub
End Class
End Namespace

Now when I tested this with two to five users with the following URLs:

User 1: http://localhost/myproject/default.aspx?TEST=0
User 2: http://localhost/myproject/default.aspx?TEST=1
User 3: http://localhost/myproject/default.aspx?TEST=2

If user 2 clicks the URL he gets:
Here is the result: 1

But if user 3 cllicks the URL he gets:
Here is the result: 3
instead of:
Here is the result: 2

Hence the intCount property remains active for every users!!! I
expect it to be a different instance for each different users.
How come is it being shared???

I am using Windows 2000 Server, ASP.NET 2003, & Framework 1.1

Hope someone can help me... Should I simply just use
Session("intCount") instead or even Application("intCounter")?
 
G

Guest

How can I keep track of a variable scope throughout veveral web pages other than using Sessions

I tried to use Shared member with a module but the problem is that it keeps the session in memory. So if you have 2 browsers open and on a click event in browser 1 you set shared variable stores to "Hello World" then switched to browser 2 the shared variable will have the value of "Hello World"..

Then instead of using a Module I changed it to a Shared property within a class but it resulted in the same bug..

You should try it..

Create a project
Add a Class.vb and call it component and copy and paste this code

Namespace tes
Public Class componen
Private Shared m_strReportName As String = String.Empt

Public Shared Property strReportName() As Strin
Ge
Return m_strReportNam
End Ge

Set(ByVal Value As String
m_strReportName = Valu
End Se
End Propert
End Clas
End Namespac

In you WebForm1.aspx.vb (code behind) copy and paste this
Namespace tes
Public Class WebForm
Inherits System.Web.UI.Pag

#Region " Web Form Designer Generated Code

'This call is required by the Web Form Designer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(

End Su
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButto
Protected WithEvents LinkButton2 As System.Web.UI.WebControls.LinkButto

'NOTE: The following placeholder declaration is required by the Web Form Designer
'Do not delete or move it
Private designerPlaceholderDeclaration As System.Objec

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Ini
'CODEGEN: This method call is required by the Web Form Designe
'Do not modify it using the code editor
InitializeComponent(
End Su

#End Regio

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
If Not Page.IsPostBack The
If Not component.strReportName = "" The

End I
End I
End Su

Private Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Clic
component.strReportName = "Hello World 1
Response.Write(component.strReportName
End Su

Private Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Clic
Response.Write(component.strReportName
End Su
End Clas
End Namespac

In your WebForm1.aspx html copy and paste the following
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="bugdemo.test.WebForm1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>WebForm1</title><meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"></head><body ms_positioning="GridLayout"><form id="Form1" method="post" runat="server"><asp:linkbutton id="LinkButton1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server">Browser 1 Click This</asp:linkbutton><asp:linkbutton id="LinkButton2" style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 32px
runat="server">Browser 2 Click This</asp:linkbutton></form></body></html

Now open two browsers and follow instructions... You will see that when you click on the link "Browser 2 Click This" in browser two the value of strReportName should have been empty instead it contains the value of strReportName set in browser 1

So my question is how can I resolve this problem

Yama Kamya

----- vMike wrote: ----

Maybe this will help
Modules are a reference type similar to classes, but with some importan
distinctions. The members of a module are implicitly Shared and scoped to
the declaration space of the standard module's containing namespace, rather
than just to the module itself. Unlike classes, modules can never be
instantiated, do not support inheritance, and cannot implement interfaces.
 
V

vMike

Here is what you need to do. In your class.vb add the following

Public Sub New
MyBase.New
me.m_strReportName = ""

End Sub

In your webform.aspx.vb do the following.

dim myReport as New component

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Handles MyBase.Load
If Not Page.IsPostBack Then
If Not myreport.strReportName = "" Then

End If
End If
End Sub

Private Sub LinkButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Handles LinkButton1.Click
myreport.strReportName = "Hello World 1"
Response.Write(myreport.strReportName)
End Sub

Private Sub LinkButton2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Handles LinkButton2.Click
Response.Write(myreport.strReportName)
End Sub
End Class


Yama said:
How can I keep track of a variable scope throughout veveral web pages other than using Sessions?

I tried to use Shared member with a module but the problem is that it
keeps the session in memory. So if you have 2 browsers open and on a click
event in browser 1 you set shared variable stores to "Hello World" then
switched to browser 2 the shared variable will have the value of "Hello
World"...
Then instead of using a Module I changed it to a Shared property within a
class but it resulted in the same bug...
You should try it...

Create a project:
Add a Class.vb and call it component and copy and paste this code:

Namespace test
Public Class component
Private Shared m_strReportName As String = String.Empty

Public Shared Property strReportName() As String
Get
Return m_strReportName
End Get

Set(ByVal Value As String)
m_strReportName = Value
End Set
End Property
End Class
End Namespace

In you WebForm1.aspx.vb (code behind) copy and paste this:
Namespace test
Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton2 As System.Web.UI.WebControls.LinkButton

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
If Not component.strReportName = "" Then

End If
End If
End Sub

Private Sub LinkButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LinkButton1.Click
component.strReportName = "Hello World 1"
Response.Write(component.strReportName)
End Sub

Private Sub LinkButton2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LinkButton2.Click
Response.Write(component.strReportName)
End Sub
End Class
End Namespace

In your WebForm1.aspx html copy and paste the following:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="bugdemo.test.WebForm1"%><!DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN"><html><head><title>WebForm1</title><meta name="GENERATOR"
content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE"
content="Visual Basic .NET 7.1"><meta name="vs_defaultClientScript"
content="JavaScript"><meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5"></head><body
ms_positioning="GridLayout"><form id="Form1" method="post"
runat="server"><asp:linkbutton id="LinkButton1" style="Z-INDEX: 101; LEFT:
8px; POSITION: absolute; TOP: 8px" runat="server">Browser 1 Click
This said:
runat="server">Browser 2 Click This</asp:linkbutton></form></body></html>

Now open two browsers and follow instructions... You will see that when
you click on the link "Browser 2 Click This" in browser two the value of
strReportName should have been empty instead it contains the value of
strReportName set in browser 1.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top