Instance: Creating a globally unique identifier in asp.net

Source: Internet
Author: User
Tags command line integer requires web services visual studio
Asp.net| Create

The globally unique identifier consists of a 128-bit integer that you can use to enter any computer that needs to enter a unique identifier or any network that requires a unique identifier. Tony Patton explains how the. NET Framework teaches you to create your own globally unique identifier.

TechRepublic's Free.net newsletter is published every Wednesday, in discussions such as Web services, asp.net, ado.net, and Visual Studio. NET, it gives examples of useful hints and encodings. You can subscribe now.

When Windows developers need a unique value, they typically use a globally unique identifier. Microsoft describes a unique number using the term globally unique identifier, which identifies an entity such as word text.

A globally unique identifier consists of a 128-bit integer (16 bytes) that you can use to enter any computer that needs to enter a unique identifier or any network that requires a unique identifier. The likelihood of this type of identifier being replicated is very small.

This article explains how the. NET Framework helps you create your own globally unique identifier.

Wherever you are, you will see that the globally unique identifier always operates in a Windows environment. When you read the registry carefully in the Windows system, you will find that the globally unique identifier is widely used to identify applications and so on. In HKEY_CLASSES_ROOT, it is even used as an identifier for the application software.

936DA01F-9ABD-4D9D-80C7-02AF85C822A8 is a typical format for globally unique identifiers.

Create a globally unique identifier with. Net

Having a globally unique identifier makes it easier to store or retrieve information. This is especially true when it comes to databases, because a globally unique identifier can help you set up a good primary key.

Similarly, SQL Server supports a globally unique identifier that can store a globally unique identifier for a uniqueidentifier data type. You can set an identifier value in SQL Server using the NEWID () feature, or you can set the identifier value in another system and then manually insert the value into SQL Server.

The latter approach is straightforward in. NET. The basic system classes in the. NET Framework include the value types of globally unique identifiers. In addition, this value type includes a method that uses a globally unique identifier value. And the Nweguid rule allows you to easily create a new global unique identifier.

The following C # command-line application shows how it ' s used:

The following command line describes how to create a globally unique identifier in C + +:

Using System;

Namespace Displayguid {

Class Guidexample {

static void Main (string[] args) {generateguid ();

}

static void Generateguid () {Console.WriteLine ("GUID:" + System.Guid.NewGuid (). ToString ());

} } }



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.