Function ASP.NET uses to generate Session ID?

我们两清 提交于 2019-12-21 18:36:30

问题


Does ASP.NET expose the underlying function it uses to generate session IDs? I want to generate a session token for use in a web service, but it will not be put in the Set-Cookie header. If ASP.NET already has a function I can use to generate a session ID this will save me from having to roll my own.


回答1:


Reflector is your friend:

SessionIDManager.CreateSessionID()

internal static string Create(ref RandomNumberGenerator randgen)
{
    if (randgen == null)
    {
        randgen = new RNGCryptoServiceProvider();
    }
    byte[] data = new byte[15];
    randgen.GetBytes(data);
    return Encode(data);
}



回答2:


Can't you do System.Guid.NewGuid().ToString()?




回答3:


I'm not sure what ASP.Net uses under the hood, but you should be able to use System.Guid.NewGuid().ToString() to come up with a unique value.



来源:https://stackoverflow.com/questions/1228085/function-asp-net-uses-to-generate-session-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!