杀死和ASP.NET会话 [英] Kill And ASP.NET Session

查看:69
本文介绍了杀死和ASP.NET会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何通过会话ID杀死会话?

-

高飞

Does anyone know how I can kill a session by session ID ?
--
Goofy

推荐答案

是的,我理解这一点。我遇到的问题是当用户关闭并且多次重新打开应用程序并且每次生成新的

会话并消耗资源时。


真正需要的是调用类似于从会话开始运行的东西。

注意每次启动会话时,我都会在
$ b $中记录用户名和会话ID b表。每次会话结束时,我都会删除该用户的记录/

会话ID。所以在会话开始时


如果CheckSessionDatabaseRecordExists(会话(userName)

,会话(sessionID))那么

DeleteSessionDatabaseRecord(Session(" userName")),se ssion(" sessionID")

''//这就是我需要的东西

Session .kill(SessionID)

''//


结束如果


这将触发会话结束事件对于那个特定的会议和

发布其状态存储等。


干杯


Manish Bafna< ; Ma ********* @ discuss.microsoft.com写信息

新闻:6A ******************** ************** @ microsof t.com ...
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...



我有除非你已经配置为使用无cookie会话,否则

ASP.NET默认使用cookie来维护会话。事实上,cookie与

名称
$ b在硬盘上创建$ b的sessionid o如果我们删除这个cookie我认为

我们

将能够通过sessionid放弃会话。在MSDN下面查找

文档
关于如何从用户的机器上删除cookie的


删除cookie - 从用户的硬盘上物理删除它 - 是一个

修改它的变化。您不能直接删除cookie,因为

cookie位于用户的计算机上。但是,您可以让浏览器为您删除

cookie。该技术是创建一个新的cookie,其名称与要删除的cookie具有相同的

名称,但是将cookie的到期时间设置为比今天更早的

日期。当浏览器检查cookie的到期时,



浏览器将丢弃现在过时的cookie。下面的代码示例

显示了删除应用程序可用的所有cookie的一种方法:

C#复制代码

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);

}


谢谢和问候,

Manish Bafna。

MCP和MCTS


高飞写道:
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:

>有没有人知道如何按会话ID杀死会话?

-
高飞
>Does anyone know how I can kill a session by session ID ?
--
Goofy



" Goofy" < me@mine.com写了留言

新闻:英国************* @ TK2MSFTNGP02.phx.gbl ...
"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...!


真正需要的是调用类似于从会话中运行的东西

start。注意每次我开始一个会话时,我都会在表格中记录用户名和会话ID

。每次会话结束时,我都会删除该用户的记录/

会话ID。所以在会话开始时


如果CheckSessionDatabaseRecordExists(Session(userName)

,Session(sessionID))则
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



如上所述,关闭并重新打开应用程序

会生成一个* new *会话。作为一个* new *会话将有一个* new * SessionID

(好吧,在每个场景中并不总是这样,但它几乎总是如此
是的,肯定上面的代码将(几乎)永远不会返回True

因为新会话将(几乎)总是有一个新的SessionID ...?

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...?


''//这就是我需要的东西

Session.kill(SessionID)

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



Session对象的每个方法都在* current *

会话上运行 - 没有传递SessionID的机制......
http://msdn2.microsoft.com/en-gb/library/ms524319.aspx


如果你的意思是来自会议本身(就像在另一个应用程序中),你就不能。


如果来自同一会话:Session.Abandon


Ju一个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/

=========== ========================

高飞 < me@mine.com在消息新闻中写道:ur ************** @ TK2MSFTNGP02.phx.gbl ...
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...

有没有人知道如何通过会话ID杀死会话?

高飞
Does anyone know how I can kill a session by session ID ?
Goofy



这篇关于杀死和ASP.NET会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆