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

Public function scope in modules

P: n/a
I'm getting some strange results in an asp.net web application that has
recently gone live.

In the header of almost all the pages, the full name of the currently logged
in user is displayed. On occasion, this changes to the name of some other
user currently on the site.

Needless to say, some find this disconcerting.

The routines that get and display the name are incredibly straight forward
and I am at a loss as to how it could happen at all. The only thing I can
think of is that public functions in modules are in the application scope.
Can someone confirm this? I can't seem to find a definitive answer anywhere.

Here's a quick sketch of how the code is currently working.

There is a file, called "header.ascx" that is included at the top of every
aspx page. In this file on the Page_Load is this code:

oUser = GetUserObject()
If Not (oUser Is Nothing) Then
If IsLen(oUser.FullName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If

The function "GetUserObject" returns another object, clsUser. It is equally
simple and declared publicly in a module:

Public Function GetUserObject() As clsUser
Dim oUser As New clsUser
Dim oCookie As HttpCookie
Dim lngUserID As Long

oCookie = HttpContext.Current.Request.Cookies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value

If lngUserID > 0 Then
If oUser.LoadObjbyUserID(lngUserID) Then
'Log?
End If
Else
oUser = Nothing
End If
End If

Return oUser

End Function

Any help or feedback would be appreciated.
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
My first thought is that the browser is caching old pages.

There are 3 levels on which caching happens
- browser
- proxy
- server

Are you sure there isnt some form of caching happening? MAybe you cache the
page on the server or send a cache-contorl header to the client.

A definite way to find out if caching is the problem is to isntruct the person
who experience the problem to hit "CTRL-F5" on internet explorer.
This will request the page and bust through all caching mechanisms. If suddenly
he sees his own name thjat meant there was some cahing going on.

If your GetUserObject function does whats its supposed to do this is probably
the reason.

I hope it helps...

Cheers,
Tom Pester
I'm getting some strange results in an asp.net web application that
has recently gone live.

In the header of almost all the pages, the full name of the currently
logged in user is displayed. On occasion, this changes to the name of
some other user currently on the site.

Needless to say, some find this disconcerting.

The routines that get and display the name are incredibly straight
forward and I am at a loss as to how it could happen at all. The only
thing I can think of is that public functions in modules are in the
application scope. Can someone confirm this? I can't seem to find a
definitive answer anywhere.

Here's a quick sketch of how the code is currently working.

There is a file, called "header.ascx" that is included at the top of
every aspx page. In this file on the Page_Load is this code:

oUser = GetUserObject()
If Not (oUser Is Nothing) Then
If IsLen(oUser.FullName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If
The function "GetUserObject" returns another object, clsUser. It is
equally simple and declared publicly in a module:

Public Function GetUserObject() As clsUser
Dim oUser As New clsUser
Dim oCookie As HttpCookie
Dim lngUserID As Long
oCookie = HttpContext.Current.Request.Cookies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value
If lngUserID > 0 Then
If oUser.LoadObjbyUserID(lngUserID) Then
'Log?
End If
Else
oUser = Nothing
End If
End If
Return oUser

End Function

Any help or feedback would be appreciated.

Nov 19 '05 #2

P: n/a
Using Modules is generally a very bad idea. It breaks the concept of
encapsulation, which is one of the cornerstones of object-oriented
programming. VB.Net LOOKS like VB, but it certainly is not.

A Module is a static class in which everything in the Module is both static
(Shared), meaning only one instance, and everything in it is global to the
entire DLL it resides in. Furthermore, in their efforts to accomodate VB
developers, Microsoft deemed that one need not even reference the class name
of the Module in order to reference its methods and properties.

I would suggest changing the Module to a class, and avoid using anything
that is static (Shared) until you understand the nature of static (shared)
methods and properties fully. They are not thread-safe, and easy to abuse.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Chris B." <ch****@sagekey.nospam.com> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
I'm getting some strange results in an asp.net web application that has
recently gone live.

In the header of almost all the pages, the full name of the currently
logged in user is displayed. On occasion, this changes to the name of some
other user currently on the site.

Needless to say, some find this disconcerting.

The routines that get and display the name are incredibly straight forward
and I am at a loss as to how it could happen at all. The only thing I can
think of is that public functions in modules are in the application scope.
Can someone confirm this? I can't seem to find a definitive answer
anywhere.

Here's a quick sketch of how the code is currently working.

There is a file, called "header.ascx" that is included at the top of every
aspx page. In this file on the Page_Load is this code:

oUser = GetUserObject()
If Not (oUser Is Nothing) Then
If IsLen(oUser.FullName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If

The function "GetUserObject" returns another object, clsUser. It is
equally simple and declared publicly in a module:

Public Function GetUserObject() As clsUser
Dim oUser As New clsUser
Dim oCookie As HttpCookie
Dim lngUserID As Long

oCookie = HttpContext.Current.Request.Cookies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value

If lngUserID > 0 Then
If oUser.LoadObjbyUserID(lngUserID) Then
'Log?
End If
Else
oUser = Nothing
End If
End If

Return oUser

End Function

Any help or feedback would be appreciated.

Nov 19 '05 #3

P: n/a
Oh Dear. Yes pls stay away from modules! And use option strict and practice
safe coding.

Cheers,
Tom Pester
Using Modules is generally a very bad idea. It breaks the concept of
encapsulation, which is one of the cornerstones of object-oriented
programming. VB.Net LOOKS like VB, but it certainly is not.

A Module is a static class in which everything in the Module is both
static (Shared), meaning only one instance, and everything in it is
global to the entire DLL it resides in. Furthermore, in their efforts
to accomodate VB developers, Microsoft deemed that one need not even
reference the class name of the Module in order to reference its
methods and properties.

I would suggest changing the Module to a class, and avoid using
anything that is static (Shared) until you understand the nature of
static (shared) methods and properties fully. They are not
thread-safe, and easy to abuse.

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Chris B." <ch****@sagekey.nospam.com> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
I'm getting some strange results in an asp.net web application that
has recently gone live.

In the header of almost all the pages, the full name of the currently
logged in user is displayed. On occasion, this changes to the name of
some other user currently on the site.

Needless to say, some find this disconcerting.

The routines that get and display the name are incredibly straight
forward and I am at a loss as to how it could happen at all. The only
thing I can think of is that public functions in modules are in the
application scope. Can someone confirm this? I can't seem to find a
definitive answer anywhere.

Here's a quick sketch of how the code is currently working.

There is a file, called "header.ascx" that is included at the top of
every aspx page. In this file on the Page_Load is this code:

oUser = GetUserObject()
If Not (oUser Is Nothing) Then
If IsLen(oUser.FullName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If
The function "GetUserObject" returns another object, clsUser. It is
equally simple and declared publicly in a module:

Public Function GetUserObject() As clsUser
Dim oUser As New clsUser
Dim oCookie As HttpCookie
Dim lngUserID As Long
oCookie = HttpContext.Current.Request.Cookies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value
If lngUserID > 0 Then
If oUser.LoadObjbyUserID(lngUserID) Then
'Log?
End If
Else
oUser = Nothing
End If
End If
Return oUser

End Function

Any help or feedback would be appreciated.

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.