Kanishka
Kanishka

Reputation: 1137

Session state in web.config

I am working on a web application which has 3 kinds of users.

To avoid multiple login of the same user I have used a signin column in the table which will become 1 after signin and 0 after signout. I have used session state to signout the user if he closes the browser window without signing out.

<system.web>       
  <sessionState mode="InProc" timeout="15" cookieName="student"/>

Global.asax :

void Session_End(object sender, EventArgs e) 
{
        int sid = Convert.ToInt32(Session["student"]);
        candidate.signoutUser(sid);
}

But there are three kinds of users. I am not able to add multiple sessionState. Is there a way to solve this problem?

Upvotes: 8

Views: 19837

Answers (1)

Farzin Zaker
Farzin Zaker

Reputation: 3606

Why you don't add user type to its session state ?

like this :

Session["user"] = "Strudent_" + userId;

and then parse your single session to find Id and user type :

var userType = Session["user"].ToString().split('_')[0];
var userId = Convert.ToInt32(Sessionp["user"].ToString().split('_')[1];)

But I recommend to use to session states :

  • one for userId
  • one for userType

you can also query for user type from database using userId if you don't want to use multiple session states too.

Upvotes: 4

Related Questions