dso
dso

Reputation: 9580

Function ASP.NET uses to generate Session ID?

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.

Upvotes: 4

Views: 1628

Answers (3)

edosoft
edosoft

Reputation: 17271

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

Upvotes: 5

David
David

Reputation: 73564

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.

Upvotes: 0

Dante
Dante

Reputation: 3891

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

Upvotes: 1

Related Questions