Implement the verification code for numbers and characters under ASP.NET

xiaoxiao2021-03-06  113

Author: kwklover (original) Source: 9CBS

The verification code that implements the numbers and characters under ASP.NET often sees a post in the forum to realize the verification code. In fact, there are many articles on the verification code in 9cbs, dev-club, etc., but a lot The article only explains how to output a randomly generated digital or character. Of course, this is the core of the verification code, but for many ASP.NET's beginners, how to use the image it generated again. One problem (there are many forums asking this), this is a reason I wrote this article. The words come true, about the principle of the verification code, I will not say more, you can see other articles, the end of the article is accompanying the instance code, There is a detailed comment, you can skip the explanation, use first, I want to talk about the usage of session and viewstate, because it will be stored in the session: session ("key") = "TEST "From session: DIM TestValue As String = Session (" Key ") Similar: Store data in ViewState: ViewState (" key ") =" Test "Take the value from ViewState: DIM TestValue As string = viewState "Key") About ViewState's more detailed information, you can see MSDN's << ASP.NET ViewState to study >> One article is better than seeing, sometimes the code is more expressive than any explanation, so it is not right here. The code explanation is too much. The verification code implemented in this article needs to use two files: GIF.ASPX This file is used to generate the verification code Validatecode.aspx This file is used to test the verification code (ie, how to use) GIF.ASPX Complete code: <% @ import namespace = "system"%> <% @ import namespace = "system.io"%> <% @ import namespace = "system.drawing"%> <% @ Import namespace = "system.drawing .Imaging "%>