简体   繁体   中英

how to handle session in mutliple tabs in a browser in c#

I am using asp.net C# and am unable to manage sessions per multiple tabs. The scenario for my website is, USER logs in, then Selects a job and then Apply for that job, and when user applies, an entry is done in database against that request. It will store, selected job ID, and Email id of that user.

By problem which i am facing is, if i open login page in a browser in 2 different tabs. the entry data gets messed up. for example, USER A selected job 1, and user B selected job 2, when i press apply button from user B, his selected job, and user A's email id are entered in database.

I tried to solve this problem by checking if the session object is NULL/empty, only then a new session should be created. else, the other user should get error that he cant login. but my code doesn't work every time. It gives me result sometimes, and sometimes it just simply doesn't run. here is my code:

protected void session_create(string s)
{
    if (string.IsNullOrEmpty((string)Session[s]))
    {
        Session[s] = s;
        test.Text = "Welcome user,  " + (string)(Session[s]);
    }
    else
    {
        test.Text = "You are Already logged in";
    }
}

and then i call this method on_submit button:

session_create("email");

because im storing only email variable, i am passing email parameter.

where,

string email = emailtextbox.Text;

So, anybody has any idea how can i resolve this issue? a user shouldn't be allowed to login in multiple tabs from a same browser. please help.

You can solve this by using InProc session state, in your WEB.CONFIG.

View this link for more information : http://www.codeproject.com/Questions/364203/Stop-Sharing-Session-State-between-Multiple-Tabs-o

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM