[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2012-03-26
5
Medium Priority
?
325 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
[X]
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
5 Comments
 
LVL 21

Assisted Solution

by:masterpass
masterpass earned 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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