确保在asp.net中的随机数 [英] secure random numbers in asp.net

查看:131
本文介绍了确保在asp.net中的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知随机()是初始化为当前时间。如果两个连接在同一秒中达到我应该得到相同的两个随机数?随着大型网站,可以是可能的。锁是坏的,所以我应该怎么解决呢?注意:数用于会话ID

From what i know Random() is initialize to the current time. If two connections hit during the same second i should get the same two random numbers? With a large site that can be likely. Locking is bad so how should i solve it? note: the number is used for the session id.

-edit-我使用的是长期坚持。感到不对劲缩短1个128bit的GUID

-edit- i am stuck using a long. It feels wrong to shorten a 128bit GUID

推荐答案

首先,为什么你需要创建自己的会话ID?您是否使用 SessionIDManager ?我会使用像什么示于示例中的Guid.NewGuid()方法<一href=\"http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionidmanager.createsessionid.aspx\"相对=nofollow> CreateSessionID
。根据对 Guid.NewGuid的文档(), 新的Guid的值将是全零或等于任何其它的Guid的几率​​是很低的。

First, why do you need to create your own session id? Are you using SessionIDManager ? I would use the Guid.NewGuid() method like what is shown in in the example CreateSessionID . According to the documentation for Guid.NewGuid(), "The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low."

这篇关于确保在asp.net中的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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