开发者

Forms Authentication update user status after specific user session ends

Hi I'm using Forms Authentication for authentication users in my asp.net c# application. How can I update user 开发者_如何学Cstatus after specific user session ends (automatically) or browser close?

Thank you


Depends on how you're storing session.

If you're using InProc, then you can hook into the Session_End application event in Global.asax:

protected void Session_End(Object sender, EventArgs e)
{
    // Remove user session
}

If you're not using InProc (ie you're using SQLState, ASP.NET State Service, etc), then you'll need to write a custom HttpModule. Here is a decent example on codeproject.

Note that this will only handle expired sessions, ie server-side session.

A browser close is a client-side event, so to handle a browser close event immediately (ie not relying on the timeout to happen some time later on the server), you'll need to write client-side code.

You're best bet is hook into the onbeforeunload event:

<body onbeforeunload="handleBrowserCloseEvent()">

The function will need to make an AJAX call to your server to expire the session.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜