473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Kill And ASP.NET Session

Does anyone know how I can kill a session by session ID ?
--
Goofy
Dec 15 '06 #1
13 9911
Yes, I understand this. The problem I have is when users who close and
reopen the application several times and each time they generate new
sessions and consume resources.

What really need is to invoke something like to be run from session start.
Note Each time I start a session I log the username and session ID in a
table. Each time the session ends I delete the record for that user /
session ID. So on session start

If CheckSessionDatabaseRecordExists( Session("userName")
,Session("sessionID") ) then
DeleteSessionDatabaseRecord(Session("userName"),Se ssion("sessionID")

'//This is what I need
Session.kill(SessionID)
'//

End if

this would fire the session end event for that particular session and
release its state storage etc.

Cheers

"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:6A**********************************@microsof t.com...
Hi,
I have read that unless you have configured to use cookieless session,the
ASP.NET by default uses cookies to maintain sessions.In fact cookie with
name
of sessionid is created on hard disk.So if we delete this cookie i think
we
would be able to abandon session by sessionid.Find below MSDN
Documentation
on how to delete cookie from user's machine:
Deleting a cookie-physically removing it from the user's hard disk-is a
variation on modifying it. You cannot directly remove a cookie because the
cookie is on the user's computer. However, you can have the browser delete
the cookie for you. The technique is to create a new cookie with the same
name as the cookie to be deleted, but to set the cookie's expiration to a
date earlier than today. When the browser checks the cookie's expiration,
the
browser will discard the now-outdated cookie. The following code example
shows one way to delete all the cookies available to the application:

C# Copy Code
HttpCookie aCookie;
string cookieName;
int limit = Request.Cookies.Count;
for (int i=0; i<limit; i++)
{
cookieName = Request.Cookies[i].Name;
aCookie = new HttpCookie(cookieName);
aCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(aCookie);
}

Thanks and Regards,
Manish Bafna.
MCP and MCTS

"Goofy" wrote:
>Does anyone know how I can kill a session by session ID ?
--
Goofy

Dec 15 '06 #2
"Goofy" <me@mine.comwrote in message
news:uK*************@TK2MSFTNGP02.phx.gbl...
Yes, I understand this. The problem I have is when users who close and
reopen the application several times and each time they generate new
sessions and consume resources.
Yes, that's right - this behaviour is by design - hack about with it at your
peril...!
What really need is to invoke something like to be run from session
start. Note Each time I start a session I log the username and session ID
in a table. Each time the session ends I delete the record for that user /
session ID. So on session start

If CheckSessionDatabaseRecordExists( Session("userName")
,Session("sessionID") ) then
As you correctly state above, closing and re-opening the application
generates a *new* session. As a *new* session will have a *new* SessionID
(OK, this isn't absolutely always the case in every single scenario, but it
almost always is), surely the above code will (almost) never return True
because the new session will (almost) always have a new SessionID...?
'//This is what I need
Session.kill(SessionID)
'//
Every single method of the Session object operates on the *current*
session - there is no mechanism for passing in a SessionID...
http://msdn2.microsoft.com/en-gb/library/ms524319.aspx
Dec 15 '06 #3
If you mean from outside the session itself ( like in another application ), you can't.

If from within the same session : Session.Abandon


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Goofy" <me@mine.comwrote in message news:ur**************@TK2MSFTNGP02.phx.gbl...
Does anyone know how I can kill a session by session ID ?
Goofy

Dec 15 '06 #4
In my scenario, each time a user gets a new session, they get a record in
the whosOn table which records the time, userName and session ID.

So they access the application, close the window and access the application
again before the first session times out two sessions would be recorded in
whosOn. My mistake on the function, it should have read.

If CheckSessionDatabaseRecordExists( Session("userName") Then

eithe kill the session for that record or simply delete it from the
database

End If

Now created the new record.

The approach I have taken in light of what you say and what I have read, is
that I simply delete the previous records with the same username before
creating a new one. When the old sessions time out there will be nothing for
them to delete.

It would be tidier though if you could kill the old sessions to preserve
resources. Its perhaps not so important in small applications, but when
there are hundreds of users on line, this could lead to problems.

Thanks for your input though.


>>
If CheckSessionDatabaseRecordExists( Session("userName")
,Session("sessionID") ) then

As you correctly state above, closing and re-opening the application
generates a *new* session. As a *new* session will have a *new* SessionID
(OK, this isn't absolutely always the case in every single scenario, but
it almost always is), surely the above code will (almost) never return
True because the new session will (almost) always have a new SessionID...?
> '//This is what I need
Session.kill(SessionID)

Dec 15 '06 #5
If you use this product to manage session (the license may be free
if you only have one server), you can definitely do this.

It supports in memory session access from within or
outside the individual session. You can also share session
in memory across servers on a farm and application domains.

It basically gives you way to create a unique key and reference
what is stored under that key from any app on any server
regardless of application domain.

http://www.eggheadcafe.com/articles/scaleout_server.asp

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Goofy" <me@mine.comwrote in message
news:ur**************@TK2MSFTNGP02.phx.gbl...
Does anyone know how I can kill a session by session ID ?
--
Goofy
Dec 15 '06 #6
I'll take a look, thanks for your help.

"Robbe Morris [C# MVP]" <jo*****@joe.comwrote in message
news:B8**********************************@microsof t.com...
If you use this product to manage session (the license may be free
if you only have one server), you can definitely do this.

It supports in memory session access from within or
outside the individual session. You can also share session
in memory across servers on a farm and application domains.

It basically gives you way to create a unique key and reference
what is stored under that key from any app on any server
regardless of application domain.

http://www.eggheadcafe.com/articles/scaleout_server.asp

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Goofy" <me@mine.comwrote in message
news:ur**************@TK2MSFTNGP02.phx.gbl...
>Does anyone know how I can kill a session by session ID ?
--
Goofy

Dec 15 '06 #7
"Goofy" <me@mine.comwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...
It would be tidier though if you could kill the old sessions to preserve
resources. Its perhaps not so important in small applications, but when
there are hundreds of users on line, this could lead to problems.
Several options, then:

1) Make the sessions as small as possible

2) Reduce the Session.Timeout from its default of 20 minutes

3) Add more memory to your webserver

4) Use SQL Server to manage state instead of InProc
Dec 15 '06 #8
I dont think option (2) will go down too well, so initially I think option
(3) is the quick and easy answer as option (4) may have its own inherent
problems.

I've heard of strange things happening when state is not managed inproc.
(not saying it cant work ), but no point in adding extra risk if I can avoid
it.

Thanks for your help.
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Goofy" <me@mine.comwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...
>It would be tidier though if you could kill the old sessions to preserve
resources. Its perhaps not so important in small applications, but when
there are hundreds of users on line, this could lead to problems.

Several options, then:

1) Make the sessions as small as possible

2) Reduce the Session.Timeout from its default of 20 minutes

3) Add more memory to your webserver

4) Use SQL Server to manage state instead of InProc

Dec 15 '06 #9
"Goofy" <me@mine.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I dont think option (2) will go down too well,
You might be pleasantly surprised, in fact...
so initially I think option (3) is the quick and easy answer
Well, it's certainly quick and easy - if you are maxed out on your server's
RAM capacity, you could always look at throwing more hardware at the problem
by getting more servers and using NLBS...
as option (4) may have its own inherent problems.
Such as...?
I've heard of strange things happening when state is not managed inproc.
Like what...?
(not saying it cant work )
Well, obviously it *can* work otherwise it wouldn't be there...
Dec 15 '06 #10
re:
>as option (4) may have its own inherent problems.
Such as...?
>I've heard of strange things happening when state is not managed inproc.
Like what...?
Like Session_End not firing... ?


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
"Goofy" <me@mine.comwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
>I dont think option (2) will go down too well,

You might be pleasantly surprised, in fact...
>so initially I think option (3) is the quick and easy answer

Well, it's certainly quick and easy - if you are maxed out on your server's RAM capacity, you
could always look at throwing more hardware at the problem by getting more servers and using
NLBS...
>as option (4) may have its own inherent problems.

Such as...?
>I've heard of strange things happening when state is not managed inproc.

Like what...?
>(not saying it cant work )

Well, obviously it *can* work otherwise it wouldn't be there...

Dec 15 '06 #11
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I've heard of strange things happening when state is not managed inproc.
Like what...?

Like Session_End not firing... ?
Yes indeed, but that's by design, not strange or unexpected...
Dec 15 '06 #12
re:
Yes indeed, but that's by design, not strange or unexpected...
heh, heh...

I find some "by design" behaviors quite strange.

;-)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:uk**************@TK2MSFTNGP06.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>>I've heard of strange things happening when state is not managed inproc.
Like what...?

Like Session_End not firing... ?

Yes indeed, but that's by design, not strange or unexpected...

Dec 15 '06 #13
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
re:
>Yes indeed, but that's by design, not strange or unexpected...

heh, heh...

I find some "by design" behaviors quite strange.

;-)
Ah yes, but that's a different argument... :-)

E.g. why doesn't HttpWebRequest implement IDisposable...? Did they just
forget...?
Dec 15 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Fred | last post by:
There is a setting in INIT.ORA that has the unintended side-effect of making sure the ALTER SYSTEM KILL SESSION command has immediate affect. Without this setting, I've seen some instances where...
2
by: yabba | last post by:
w2k server as webadmin i have occasion to kill a user session and couse them to login again. I have the sessionID saved in a file. is there a way to kill the user session without disturbing...
2
by: Fabrice | last post by:
Hello, I 'would like to build a system (based on database, not SqlServer but MySQL) to permit only one session per user. I'm using a form athentication. My Solution : --------------- When...
0
by: HM | last post by:
Hello ! To kill a session i used KILL -INT <PID>. This command wasn't successfull. The processus is still here when an 'ps ax' or a 'select * from pg_stat_activity' Is there an other way to...
4
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which...
3
by: Mangler | last post by:
I have 2 sessions that get created. One when the user logs in called "uname" and another called "idrma" when that user choses to begin a repair request. I know <%session.abandon% will kill both...
3
Nikky
by: Nikky | last post by:
I m sending a session from 1 form to another form i want to kill that session when i came back to first form how can i do this. i m using more than one session at a time but i want to kill ...
4
by: mritunjay82 | last post by:
If any user is deleted from admin section and is still logged in he can keep on doing things on my website that need to be logged in. I want to kill this users session. The only possible way I...
3
by: spectrumdt | last post by:
Hello. I am running Fedora Linux and KDE, using the Konsole command line. When coding Python, I regularly make a bug causing my program to not terminate. But how do I kill the non-terminating...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.