如何在 C# 中获取会话 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12367571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:01:12  来源:igfitidea点击:

How to get Session Id In C#

c#sessionid

提问by Champ

what is the correct way to get session id in C#

在 C# 中获取会话 ID 的正确方法是什么

String sessionId ;
sessionId = Session.SessionID;

or

或者

 string sessionId = Request["http_cookie"];
 sessionId = sessionId.Substring(sessionId.Length - 24);

Actually i am totally new to C# and just jumped in a project where i find the second code and by Google i found the first code so anyone please tell me what is the actual code to be used

实际上,我对 C# 完全陌生,只是跳入了一个项目,在那里我找到了第二个代码,通过 Google 我找到了第一个代码,所以有人请告诉我要使用的实际代码是什么

采纳答案by Davecz

correct way is:

正确的方法是:

HttpContext.Current.Session.SessionID