Randomly fetching a string in an ASP. NET MVC Application

Source: Internet
Author: User

When developing an ASP. NET MVC application, it is possible to require a random string, either as a password or as a verification code.

If you need a SQL version, you can refer to "password requires special characters (ii)" http://www.cnblogs.com/insus/archive/2012/02/16/2354453.html

How much of this implementation method is referred to this implementation of C # version.


Under Application, create a CharacterUtility.cs:

In this category, there are several static methods, respectively:
One, for random lowercase letters:

Two, is randomly generated capital letters:

Three, is randomly generated numbers:

Four, is to produce special characters, character sets you can define:

Each of the above attributes can be randomly obtained one character, the following insus.net write a method to get a 8-bit length of random string, of course, you can define the length:

In the control, write an action and a method to perform for jquery:

Finally, you create a view:

Live Demo:

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.