?
Solved

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

Posted on 2012-03-26
5
Medium Priority
?
326 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 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

850 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