如何在asp.net中生成会话ID [英] How to generate session id in asp.net

查看:122
本文介绍了如何在asp.net中生成会话ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个aspx页面的网站,其中一个需要在用户进入时生成唯一的会话ID。此会话ID应该是及时结构化的字符串yyyymmddhhmmssms(年,月,日,小时,分钟,第二,milisecond)。因此,当用户访问此特定aspx页面时,用户将获得唯一的会话ID。然后,当单击完成按钮时,会话ID被触发,永远不会被重用。

I have a website with a number of aspx pages and one of them requires generating unique session id when an user comes in. This session id should be in time structured string as yyyymmddhhmmssms (year,month,day,hour,minute,second,milisecond). So when an user accesses to this particular aspx page, the user gets an unique session id. Then when finish button is clicked the session id is fired and will never be reused.

推荐答案

SessionIDManager.CreateSessionId [ ^ ]将帮助您创建会话ID 。

尝试这个答案 [ ^ ]。
SessionIDManager.CreateSessionId[^] will help you create a session id.
Try this answer[^] as well.


我不知道为什么你需要id是唯一的。据我所知,Session对用户来说是独一无二的,不能与其他用户共享。



因此,无论id是什么,它都会保存值无法在用户之间共享。
I don't know why exactly you need the id to be unique. As far as I know Session is unique to user, which can't be shared with other users.

So, whatever may be the id, it will hold values which can't be shared across users.


由于Web服务器是多线程的,因此会为访问您站点的每个用户生成唯一的会话。因此无法在用户之间共享。



因此,您不必显式创建新的session-id,webserver会为您执行此操作。



虽然,你可以使用 Guid 。并查看此处 [ ^ ]



-KR
As web server is multi-threaded it generates the unique session for each user visiting your site. So that can't be shared among the users.

Hence, you don't have to explicitly create the new session-id, webserver would do that for you.

Though, you can use Guid. And look at here[^]

-KR


这篇关于如何在asp.net中生成会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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