Obtain a random string in the ASP. net mvc application.

Source: Internet
Author: User

When developing ASP. net mvc applications, a random string may be required as a password or verification code.

If you need the SQL version, you can refer to the password needs to carry special characters (2), http://www.cnblogs.com/insus/archive/2012/02/16/2354453.html

The implementation method in this article is referring to this implementation C # version.


Under the application, create a CharacterUtility. cs:

 

There are several static methods in this category:
1. Random lowercase letters:

2. generate random uppercase letters:

 

3. Random numbers:

 

4. Special characters are generated. You can define the character set:

 

Each of the above attributes can be randomly obtained with one character. Next, Insus. NET writes another method to obtain an 8-bit random string. Of course, you can define the length:

 

 

In the widget, write an Action and a method for executing jQuery:

 

Finally, you can create a view:

 

Real-time Demonstration:

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.