473,320 Members | 2,071 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,320 software developers and data experts.

Public function scope in modules

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

Similar topics

9
by: Steven T. Hatton | last post by:
It was once suggested to me that I could accomplish much the same thing that modules would accomplish (if C++ had modules) by writing my entire program - except for main() - inside of a class. ...
38
by: Lasse Vågsæther Karlsen | last post by:
After working through a fair number of the challenges at www.mathschallenge.net, I noticed that some long-running functions can be helped *a lot* by caching their function results and retrieving...
36
by: lauren quantrell | last post by:
I'm hoping someone can tell me if there is any performance benefit in my applications between distinguishing a code routine as a Function or a Sub or if there is a performance benefit between...
3
by: thdevdex | last post by:
I'm new to the web forms world (ASP.Net) but not vb and am converting a vb6 windows app to the web. If I create public subroutines at a module level, is this a problem in a server based app? Will...
27
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
20
by: Joseph Wakeling | last post by:
Hello all, Here's a brief function from the aforementioned (and controversial) GNU Scientific Library (GSL), or rather, a slightly rewritten version of it that I've made. The function takes an...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
7
by: bambam | last post by:
import works in the main section of the module, but does not work as I hoped when run inside a function. That is, the modules import correctly, but are not visible to the enclosing (global)...
2
by: Joe Strout | last post by:
Some corrections, to highlight the depth of my confusion... On Nov 11, 2008, at 9:10 PM, Joe Strout wrote: Actually, it does not. And no, it isn't; it's the NAME of the module the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.