Variables in Global.aspx

  • Thread starter Thread starter barry
  • Start date Start date
B

barry

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
 
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
 
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?
 

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

Back
Top