473,387 Members | 1,512 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,387 software developers and data experts.

Variables in Global.aspx

Hi

I keep username and password in Global.aspx
static public string un = "";
static public string pw = "";

after a user logs in i update un and pw with the input values.

but if i start another instance of the webpage in a new instance of the
webbrowser eg http://localhost/default.aspx the value of un and pw is
changed to new values.

But if i refresh the first instance of webpage value of the 2nd instance of
un and pw is displayed.

how can i solve this problem.

barry

May 10 '06 #1
2 2327
Er... don't use static application-level variables for user specific
info. There is only ever one copy of a static member, since you're
changing a static member of the HttpApplication all your users will
have the same un/pw.

I think perhaps you've misunderstood the purpose of Global.asax - it's
not for storing global variables. Those few things which *are* global
to an application (conenction strings, URLs etc.) should be kept in
web.config so you can change them without having to recompile your
entire application.

The best place to keep user info is the session object.
Session["un"] = userName;
Session["pw"] = password;

but why keep the password anyway?

May 10 '06 #2
Barry,

Using static variables and/or the global.aspx page is not a good way to do
this. By doing so you have created application level variables. These
variables are not independent of each user but are shared by all users of
the application. Remember that this is the web. One single application with
many users. Therefore you have to use threadsafe variables for each user
that will be independent of all the others. The easiest way to do this would
be to store the information in session variables and if you still want to
keep this information in the global.aspx file you may use the
Session_OnStart method in the global.aspx:

Session["key"] = "value";

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"barry" <so*****@somewhere.com> wrote in message
news:ei***************@TK2MSFTNGP05.phx.gbl...
Hi

I keep username and password in Global.aspx
static public string un = "";
static public string pw = "";

after a user logs in i update un and pw with the input values.

but if i start another instance of the webpage in a new instance of the
webbrowser eg http://localhost/default.aspx the value of un and pw is
changed to new values.

But if i refresh the first instance of webpage value of the 2nd instance
of un and pw is displayed.

how can i solve this problem.

barry

May 10 '06 #3

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

Similar topics

3
by: Jonathan Perkins | last post by:
How do i create global variables that keep their values after the form is postback, (i.e. when a button is clicked, etc.) Thank you very much.
2
by: Bonj | last post by:
H I've got the following problem - I need to have an aspx page with two frames, although the question isn't necessarily about the workings of the frames, more session variables... the frames consist...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
6
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? ...
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
2
by: Child X | last post by:
Hi all, I am still new to .net. Coming from an asp classic background. Using classic asp, i would use a include file to contain global variables contained through out a site. These would...
4
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
10
by: Yehia A.Salam | last post by:
Hello, I was trying to connect to an Xml database, and I thought of loading the Xml Document in "Application_Start" so that the xml is loaded only once and then queried later as many times as...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.