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.