onepieceking
Well-known member
- Joined
- Sep 20, 2006
- Messages
- 64
- Programming Experience
- 1-3
I tried to prevent users from doing duplicate logins in my web application. I create a cache keyed by the user's userid upon login. During this period, if another person tries to login using the same userid, it will be stopped due to the cache. Upon logout, i will remove the cache so that the user can login again.
for logout,
I now experience this problem. If the session time out before the user logout, the cache will be there permanently. How do i remove the cache when the session time out?
VB.NET:
[COLOR=#007700]Private [/COLOR][COLOR=#0000bb]sub BtnLogin_Click[/COLOR][COLOR=#007700](byval[/COLOR][COLOR=#0000bb] sender as object[/COLOR][COLOR=#007700], byval e as [/COLOR][COLOR=#0000bb]System[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]EventArgs[/COLOR][COLOR=#007700]) handles btnlogin.click[/COLOR][COLOR=#0000bb]
[/COLOR][COLOR=#007700] [/COLOR][COLOR=#0000bb]
dim strConCat as string [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]TxtUserName[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Text[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000bb]TxtPassword[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Text[/COLOR][COLOR=#0000bb]
dim strUser as string [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Convert[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]ToString[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]Cache([/COLOR][COLOR=#0000bb]strConCat)[/COLOR][COLOR=#007700])[/COLOR][COLOR=#0000bb]
[/COLOR][COLOR=#007700]if ([/COLOR][COLOR=#0000bb]strUser is nothing[/COLOR][COLOR=#0000bb] or[/COLOR][COLOR=#007700] [/COLOR][COLOR=#0000bb]strUser = [/COLOR][COLOR=#0000bb]String[/COLOR][COLOR=#007700].Empty) then[/COLOR][COLOR=#0000bb]
[/COLOR][COLOR=#0000bb]
Cache[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]strConCat[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]strConCat)[/COLOR][COLOR=#007700]
[/COLOR][COLOR=#0000bb]Session([/COLOR][COLOR=#dd0000]"UserDetails")[/COLOR][COLOR=#007700] = [/COLOR][COLOR=#0000bb]strConCat[/COLOR][COLOR=#0000bb]
Response[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Write[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Welcome!"[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000bb]
[/COLOR][COLOR=#0000bb]
else
[/COLOR][COLOR=#0000bb]
Response[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]Write[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"Duplicate login not allowed !!"[/COLOR][COLOR=#007700])[/COLOR][COLOR=#0000bb]
[/COLOR]
[COLOR=#0000bb]end sub[/COLOR]
for logout,
VB.NET:
[COLOR=#0000bb]Cache.remove(session("UserDetails"))[/COLOR]
I now experience this problem. If the session time out before the user logout, the cache will be there permanently. How do i remove the cache when the session time out?