Last post Mar 21, 2011 06:35 AM by kratos_Vimal
Mar 20, 2011 10:44 AM|Anam|LINK
I am using ASP.NET 2.0 and Sql server 2005 for my web application.
I have a Login.aspx page where i validate Login using Stored procedure Something like that
protected void btnLogin_Click(object sender, ImageClickEventArgs e)
Session["UserName"] = Convert.ToString(rd["UserName"]);
I am Displaying this "UserName" on my masterpage like that
lbl_Name.Text = Session["UserName" <div>].ToString();</div>
But this Session expire and lbl_Name.Text become empty.
How to save this "UserName" that will display in whole website when user is active.
This is the only 1 Session variable i have used in website.
any other option to save Username ???
Mar 20, 2011 12:58 PM|smirnov|LINK
When session has expired, is the user still logged on?
Mar 21, 2011 02:34 AM|Anam|LINK
yes i want to store this Session variable into some other Global Fileds, that will b available for the user that logged in. In my web apllication the user can open their webapplication whole day.
What will be the best solution to save this User Logged in Name.???
Thanks in advance
Mar 21, 2011 04:00 AM|amitpatel.it|LINK
You can increase session expiration time, but in inproc session state mode taht has some limits.
If you want to set session expiration time as a day then I suggest please go ahead with SQL session state mode.
Mar 21, 2011 04:24 AM|Anam|LINK
Thanks for the reply!
Could u please tell me how to increase "session expiration time as a day" ??
Thanks in advance.
Mar 21, 2011 04:35 AM|amitpatel.it|LINK
You can set it in config value as below ..
But if you are using InProc you can not set it with a day becaue here session stroed in In process mean ISS process(asp.net worker process) so there are limitation to preserver session variable.
IIS 6.0: The minimum allowed value is 1 minute and the maximum is 1440 minutes.
So to set a day value as timeout then please go with sQL
For that thing you need first undertand how to store session in SQL server.
Mar 21, 2011 05:08 AM|chaiturocks|LINK
If the session is expired then user should not be able to access the application.
You need to increase your session timings.
Mar 21, 2011 05:33 AM|smirnov|LINK
When session has expired, the user must be logged off. You need to check it and if it is expired you must redirect user back to the login page.
I think you can try to use standard
Mar 21, 2011 05:47 AM|Rakeshkr|LINK
check this article
Mar 21, 2011 06:35 AM|kratos_Vimal|LINK
You can store the user name in HttpContext like this
HttpContext.Current.User = principal;
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, Context.User.Identity.Name, DateTime.Now, DateTime.Now.AddMinutes(intRoleExpireMinute), false, string.Empty, FormsAuthentication.FormsCookiePath);
and access it like this
string name = HttpContext.Current.User.Identity.Name;
The only thing being you should use Form authentication for the same