简体   繁体   中英

how to generate a HOST NAME in asp.net?

I want to automatically generate a host name whenever user log in into the web.When they click the button log in, the system will automatically create a host name to them and the data automatically save in excel for record. But, the problem is, I want to create a host name including company name eg; PEN + department name eg; IT + any 4 of random number. I'am still new in this asp.net and csharp language. Please help me.Please teach me.

This would seem to be what you're asking for

Random rand = new Random();
string hostName = companyName + departmentName + rand.Next(1000,9999).ToString();

It's better if Random rand = new Random(); is called once and not everytime you create a new hostName, because you want to avoid any possibility that 2 Random objects would have the same seed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM