Michael Bates
Michael Bates

Reputation: 1934

What are these IDs I always see in ASP.NET webapps

I always see ASP.NET apps with IDs in the URL that look something like:

aa73de9c-41ac-11e4-a47a-d4ae52c74096

How are these IDs created and what is their purpose?

Upvotes: 1

Views: 166

Answers (4)

Martin Liversage
Martin Liversage

Reputation: 106836

The ID is a string representation of a GUID or Globally Unique Identifier. A GUID is a 128 bit value (or 16 bytes) and the string representation is simply this value written using hexadecimal. The dashes are added because the GUID has an internal structure but that is not so important. The approximate number of possible GUID's is 340,000,000,000,000,000,000,000,000,000,000,000,000 which is a pretty big number.

The important thing about a GUID is that whenever you generate a new GUID (in .NET using Guid.NewGuid()) you can rely on it being unique. This means that you can generate these keys on the client without first asking the server for the next key (you do that when you generate sequential keys like 1, 2, 3 etc.)

There are several algorithms for generating GUID's. The original algorithm takes the computers network card MAC address (which is supposed to be unique) and combines that with a high resolution timestamp to create the GUID. Unfortunately, this leaks the MAC address of the generating computer and today you should probably also not rely on MAC addresses being unique. Fortunately, there exists better algorithms for generating GUID's. You can even create sequential GUID's which is kind of funny because GUID's are very good at solving the problem where you do not know what the next number in the sequence is.

The name GUID is actually a Microsoft invention but they are really the same as a UUID which is an Universally Unique Identifier. I guess that Microsoft hesitated to promise uniqueness throughout the universe but at least promises global uniqueness .

Upvotes: 2

Crab Bucket
Crab Bucket

Reputation: 6277

It's possible that the web apps you are looking at are using cookieless sessions. In this case you would get Guid embedded in the URL which would keep track of the session in the absence of a cookie being set.

The cookieless session is activated by this web.config key

<sessionState cookieless="true" />

so if you have access to the app code you could check and see if this is the issue

Upvotes: 1

BenjaminPaul
BenjaminPaul

Reputation: 2931

Its a GUID (Globally Unique Identifier), you can create them using the following method in C#

Guid.NewGuid()

They can used for anything so its hard to say that they are being used for in the scenario you mentioned but whatever it is being used for has a requirement to be unique so its could be a user session id, a product id, database record id or anything else that the website might need to keep track of.

Take a look at more information here (C#):

http://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.110).aspx

They are not unique to C# and can be found in any computer systems. GUIDs generated from random numbers normally contain 6 fixed bits (these indicate that the GUID is random) and 122 random bits; the total number of unique such GUIDs is 2122 (approximately 5.3×1036). This number is so large that the probability of the same number being generated randomly twice is negligible

Get more information on Guids from Wikipedia..

http://en.wikipedia.org/wiki/Globally_unique_identifier

Upvotes: 0

Karan
Karan

Reputation: 3328

These IDs are GUIDs and created on the server side to maintain the uniqueness.

You can create these ID's simply like this http://msdn.microsoft.com/en-us/library/system.guid.newguid%28v=vs.110%29.aspx.

Upvotes: 0

Related Questions