Extjs 3 (implement the verification code image Controller)

Source: Internet
Author: User

Original http://www.cnblogs.com/aehyok/archive/2013/04/19/3030212.html

Preface

In extjs 2 (implementing logon) Login.

Implement the verification code image Controller

1. Now add a helper directory to the project, which will be used to place helper classes, including some custom practical methods. Copy the verifycode. CS file to this directory, open the file, and add the namespace "extmvcone. helper" to it. This is done to facilitate the Controller to access this class.

Then, add a controller named verifycodecontroller to the Controller directory (controllers). Because the output is an image in the file format rather than a view, you need to change the returned actionresult type to filecontentresult. In the verifycode class, the createverifycode method can generate a 4-digit verification code, while calling the createimages method can return the byte array of the image, through which you can generate the image file,CodeAs follows:

     Public   Class Verifycodecontroller: controller {  //          //  Get:/verifycode/          Public  Filecontentresult index () {verifycode v = New  Verifycode (); V. Length = 4  ;  String Code = V. createverifycode (); //  Random Code Retrieval Session ["  Vcode  " ] = Code; V. padding = 10  ;  Byte [] Bytes = V. createimage (CODE );  Return File (bytes, @"  Image/JPEG  "  );}} 

Finally, a file consisting of byte arrays returned by createimage is returned. The file type is JPEG.

The Controller code has been completed. Now let's test whether the image can be properly displayed. Open the website in the browser and modify the address to access the verifycode controller.

The image controller of the verification code is implemented.

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.