Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
how to send a unique id on user's email address when user sign up...in asp.net c#
Posted
Comments
CHill60 13-Mar-13 13:04pm    
You're going to have to add some more detail here - sign up to what, how are you storing the user's details, do you want to know how to email or how to generate a unique id?

First you create a unique ID using whatever you would like,

You might want to look into this class,

http://msdn.microsoft.com/en-us/library/system.random.aspx[^]

Or as Mike has pointed out in the comments,

- A SQL table's Primary Key declared as an auto-incremented Identity column will create a unique id number


Then you send them an email with this unique id,

http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8[^]
 
Share this answer
 
v2
Comments
Mike Meinz 13-Mar-13 18:36pm    
Be careful. A Random Number generator does not create unique numbers. At some point, it is possible for a Random Number generator to output a number that is has previously returned.

A SQL table's Primary Key declared as an auto-incremented Identity column will create a unique id number.
DinoRondelly 13-Mar-13 18:38pm    
Your right, i have updated the solution with your remarks, Thanks
Just use the current date, time and seconds

something like below, seriously doubt you have that many emails to send to overlap the seconds

Dim uniqueID as string = DateTime.now.ToString("yymmddhms")


or for a length of 10

private string GenerateId()
        {
            long i = 1, j=-1;
            foreach (byte b in Guid.NewGuid().ToByteArray()){i *= ((int)b + 1);}
            foreach (byte b in Guid.NewGuid().ToByteArray()) { j *= ((int)b + 1); }
            var str1 = string.Format("{0:d}", (i - DateTime.Now.Millisecond));
            var str2 = string.Format("{0:d}", (j - DateTime.Now.Millisecond));
            return "EMC" + str1.Substring(0, 4) + str2.Substring(str2.Length/2, 3);
        }
 
Share this answer
 
Comments
Nelek 15-Mar-13 5:26am    
What happens when System get Date-Update in winter or summer? The probability is very little, yes, but it could still be possible to repeat an ID. I think it is better to let the Server manage with it as pointed in the comment of solution 1
jkirkerx 17-Mar-13 16:38pm    
I didn't think of that, must of been the time change, just getting over it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900