Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to check session is expired or not--possible approach

Posted on 2012-03-26
5
318 Views
Last Modified: 2012-04-25
I found the below Info at http://forums.asp.net/t/1138444.aspx

My question: "What would be the best place to initialize Session["UserId"]=User.Identity.Name; ??  "

In Session_Start(..) of Global.asax ?? Or Another Location?

The info:

Usually when its user/role based application we always store userid/username in session.

So this is a variable that an application always needs.... So you can even check the individual variable which is maitained for Session Tracking/Identification.

if (Session["UserId"] == null)
{

    Response.Redirect("Login.aspx?reason=SessionTimeout"); //Passing the reason in querystring to notify the user in Login page.
}
0
Comment
Question by:niceguy971
5 Comments
 
LVL 21

Assisted Solution

by:masterpass
masterpass earned 250 total points
ID: 37769734
Have a look here:

http://forums.asp.net/t/1283071.aspx/1

and

http://forums.asp.net/t/1667680.aspx/1

It actually does not matter where you start your session. Although the best place is Session_Start

Hope this helps!
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 250 total points
ID: 37769801
i think the best place would be when your authentication of login is complete.
Say you have Authenticate method in Login.aspx page handler.

once the use if authenticated, you can set the session there like this:-

private void Authenticate(string userid,string password)
{
if(DoAuthenticate(userid,password))
{
Session["UserId"]=userid;
}
}

private bool DoAuthenticate(string userid, string password)
{
//Authenticate here by matching the userid and password
}

Open in new window

0
 
LVL 9

Expert Comment

by:gery128
ID: 37769879
@niceguy971
Why you want to initialize Session["UserId"] ?
You already have that in User.Identity.Name which is available throughout the application. So you can access it anywhere you want in application without transferring to Session object as an additional variable.
0
 

Author Comment

by:niceguy971
ID: 37775063
Hi gery128. My original question : "How to check if session is expired?"  Per Info at

http://forums.asp.net/t/1138444.aspx it's possible to use Session["UserId"] ..or another

Session["something"]..so i was asking "What would be the best place to initialize

Session["UserId"] or Session["something"] ?"

Did you read the info at http://forums.asp.net/t/1138444.aspx ?
0
 

Author Closing Comment

by:niceguy971
ID: 37895644
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question