473,569 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.asc x" 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.Ful lName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If

The function "GetUserObj ect" 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.Cur rent.Request.Co okies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value

If lngUserID > 0 Then
If oUser.LoadObjby UserID(lngUserI D) 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 1387
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.asc x" 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.Ful lName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If
The function "GetUserObj ect" 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.Cur rent.Request.Co okies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value
If lngUserID > 0 Then
If oUser.LoadObjby UserID(lngUserI D) 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******** ******@TK2MSFTN GP09.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.asc x" 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.Ful lName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If

The function "GetUserObj ect" 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.Cur rent.Request.Co okies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value

If lngUserID > 0 Then
If oUser.LoadObjby UserID(lngUserI D) 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******** ******@TK2MSFTN GP09.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.asc x" 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.Ful lName) Then
lblLogIn.Text = oUser.FullName & logged in"
End If
End If
The function "GetUserObj ect" 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.Cur rent.Request.Co okies("UserID")

If Not oCookie Is Nothing Then
lngUserID = oCookie.Value
If lngUserID > 0 Then
If oUser.LoadObjby UserID(lngUserI D) 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
2442
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. When it was suggested, I didn't take it very seriously, but I have recently begun wondering if it is an idea worth considering. I'm now trying to...
38
2744
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 from cache instead of calculating again. This means that often I can use a natural recursive implementation instead of unwinding the recursive calls...
36
21491
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 identiying a Function as a Function or a Private Function (or Sub as a Sub or a Private Sub) in code modules. I understand that using Private...
3
1503
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 my users step on each other? I'm confused about whether global module level subroutines and variables are exposed to all users at the same time or...
27
2692
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. What is the normal way to do this? Thanks, Thomas --
20
1372
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 integer and sets up certain necessary values for a random number generator. x, n and shuffle in this function are global variables. ...
9
2337
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 = CDec(txbInv.Text) Wage = CDec(txbTotWage.Text)
7
2145
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) scope. Questions: (1) Where can I read an explanation of this? (2) Is there a work around?
2
1832
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 function is in. I'm not sure what good that does me. docstring.testmod does take an
0
7694
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...
0
7921
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. ...
1
7666
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...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
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
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.