Thursday, March 22, 2012
session variables
I want some help regarding maintaining session variables. I am writing Asp.net using C#.
Once the user logs in to the system using his login and password
I want to store his settings (line fullname, email id and other
privileges) in session variables so that I can access them
throwout the application.
How do I go about this?After a successful login you can assign items to session as such
Session("FullName") = strFullName;
'or
Session("FullName") = txtName.text; ' using a textbox
Session("Email") = strEmail;then to retrieve their values at any point...
txtName.text = Session("FullName");
In C# it is in the format:
Session["FullName"] = strFullName;
DJ
thanks guys.
Tuesday, March 13, 2012
session variables and global.aspx.cs - where do i put them?
public class Global : System.Web.HttpApplication
{
//e.g.
public static int [] count=new int[5]
}
and then refer to it in my page .cs files as Global.count[0]... [4] will
every session in my application be accessing the same count array or will
they each have their own?
I guess i am really saying is, is there a difference between the above and
:
protected void Session_Start(Object sender, EventArgs e)
{
Sesson["count"]=new int[5]
}
It strikes me that if they are the same then the first option is better
because i don't have to keep casting from object to int everytime i access
the array in web pages.Hi Tony,
You should think of the Application scope the same way you would think of Environment variables.
They are not only global, but they are also readable and writable to all users of the system at the same
time.
Session is better to use if the values are not final or need to be changed per user.
A session is created for each user making a request.
____________________________________
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Business | Personal
Session variables are mixing each other with multiple login....
When the user does multiple logins to the system and navigates to different
screens and clicks back button sometimes it reading the session variables
values are mixing each other.
How to avoid this kind of situation? Basically I am looking for the steps to
be taken when we develop web based application using ASP.Net (.Net framework
1.1) for multiple logins.
Shashii would think this would only happen if you are creating new windows in IE
from an existing one that is open. if so then they would share the same
session id. if you create a new instance of IE for each logon, then this is a
little strange.
what type of logon are you using, your own, or forms? or windows or passport?
"Shashi" wrote:
> My development environment is ASP.Net 1.1.
> When the user does multiple logins to the system and navigates to different
> screens and clicks back button sometimes it reading the session variables
> values are mixing each other.
> How to avoid this kind of situation? Basically I am looking for the steps to
> be taken when we develop web based application using ASP.Net (.Net framework
> 1.1) for multiple logins.
> Shashi
>
Thanks for your reply.
1. I am using my own login. Checking the user id and password in the
database.
2. Here is the sequence.
* Default.aspx is the default page for the website.
* Load event of this page, I am opening a new page(Login Page) using
the following java script.
Response.Write( "window.open('" & URL & "','" & "WindowName"
& Session.SessionID & "','" &
toolbar=no,location=no,titlebar=no,directories=no, status=yes,menubar=no,scro
llbars=yes,copyhistory=no,menubar=no,scrollbars=1, resizable=1,height=" &
Chr(34) & " + maxh+" & Chr(34) & ",width=" & Chr(34) & " + maxw+" & Chr(34)
& ",left=0,top=0" & "');" & vbCrLf))
* In Login page the user(U1) will login to the sytem.
*Enters Customer # and navigates to the customer page.
*Other user(U2) logs in the same way and navigates to the customer
screen.
* User2 through popup menu selects Back and navigates back.
* USer U1 through popup menu selects Back and navigates back
*Instead of displaying the U1 profile system is displaying the U2
profile. That means I have text box with user ID displayed from a session
variable which got wrong data.
Please advice.
Shashi
"chriscollinson" <chriscollinson@.discussions.microsoft.com> wrote in message
news:CCE62572-A6C0-4B20-BD91-F5E873D59CA8@.microsoft.com...
> i would think this would only happen if you are creating new windows in IE
> from an existing one that is open. if so then they would share the same
> session id. if you create a new instance of IE for each logon, then this
is a
> little strange.
> what type of logon are you using, your own, or forms? or windows or
passport?
> "Shashi" wrote:
> > My development environment is ASP.Net 1.1.
> > When the user does multiple logins to the system and navigates to
different
> > screens and clicks back button sometimes it reading the session
variables
> > values are mixing each other.
> > How to avoid this kind of situation? Basically I am looking for the
steps to
> > be taken when we develop web based application using ASP.Net (.Net
framework
> > 1.1) for multiple logins.
> > Shashi
Session variables are mixing each other with multiple login....
When the user does multiple logins to the system and navigates to different
screens and clicks back button sometimes it reading the session variables
values are mixing each other.
How to avoid this kind of situation? Basically I am looking for the steps to
be taken when we develop web based application using ASP.Net (.Net framework
1.1) for multiple logins.
Shashii would think this would only happen if you are creating new windows in IE
from an existing one that is open. if so then they would share the same
session id. if you create a new instance of IE for each logon, then this is
a
little strange.
what type of logon are you using, your own, or forms? or windows or passport
?
"Shashi" wrote:
> My development environment is ASP.Net 1.1.
> When the user does multiple logins to the system and navigates to differe
nt
> screens and clicks back button sometimes it reading the session variables
> values are mixing each other.
> How to avoid this kind of situation? Basically I am looking for the steps
to
> be taken when we develop web based application using ASP.Net (.Net framewo
rk
> 1.1) for multiple logins.
> Shashi
>
>
Thanks for your reply.
1. I am using my own login. Checking the user id and password in the
database.
2. Here is the sequence.
* Default.aspx is the default page for the website.
* Load event of this page, I am opening a new page(Login Page) using
the following java script.
Response.Write( "window.open('" & URL & "','" & "WindowName"
& Session.SessionID & "','" &
toolbar=no,location=no,titlebar=no,direc
tories=no,status=yes,menubar=no,scro
llbars=yes,copyhistory=no,menubar=no,scr
ollbars=1,resizable=1,height=" &
Chr(34) & " + maxh+" & Chr(34) & ",width=" & Chr(34) & " + maxw+" & Chr(34)
& ",left=0,top=0" & "');" & vbCrLf))
* In Login page the user(U1) will login to the sytem.
*Enters Customer # and navigates to the customer page.
*Other user(U2) logs in the same way and navigates to the customer
screen.
* User2 through popup menu selects Back and navigates back.
* USer U1 through popup menu selects Back and navigates back
*Instead of displaying the U1 profile system is displaying the U2
profile. That means I have text box with user ID displayed from a session
variable which got wrong data.
Please advice.
Shashi
"chriscollinson" <chriscollinson@.discussions.microsoft.com> wrote in message
news:CCE62572-A6C0-4B20-BD91-F5E873D59CA8@.microsoft.com...
> i would think this would only happen if you are creating new windows in IE
> from an existing one that is open. if so then they would share the same
> session id. if you create a new instance of IE for each logon, then this
is a
> little strange.
> what type of logon are you using, your own, or forms? or windows or
passport?
> "Shashi" wrote:
>
different
variables
steps to
framework