1. Template page // Create a web page template Enter the captcha text box And send the content in the text box to the back-end verification
<p> Please enter the verification code :<input type="text" name="checkcode" /><img src="/createcheckcode.ashx"/></p> // Enter your name and address
2. Server side
Reference namespace And change the type of the response to picture form
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Web.SessionState;

namespace WebApplication3
{
/// <summary>
/// createcheckcode Summary description of
/// </summary>
public class createcheckcode : IHttpHandler, IRequiresSessionState // Realization ashx
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/JPEG";// The corresponding type format
Bitmap map = new Bitmap(80,30);// The corresponding width and height
Graphics g = Graphics.FromImage(map);// Get this drawing object based on this image
g.FillRectangle(Brushes.White, 1, 1, 78, 28);// The brush color is white 、 And from 1,1 PM , The back is the width
char[] code = new char[26];// Definition 26 And store the letters in code in
for (int i = 0; i < 26; i++)
{

code[i] = (char)('a' + i);//26 Two letters start to loop

}
string checkdode = ""; // Define random numbers
Random r = new Random(); // Create random functions
for (int i = 0; i < 4; i++)
{

checkdode = checkdode + code[r.Next(0, 26)]; // Loop to write letters to

}
context.Session["checkdode"] = checkdode;// Store a copy of
g.DrawString(checkdode, new Font(" In black ", 20), Brushes.Black, new PointF(2, 2));// Random and then random drawing in the image
map.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);// The type of image to respond to

}

public bool IsReusable
{
get
{
return false;
}
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;

namespace WebApplication3
{
/// <summary>
/// dl Summary description of
/// </summary>
public class dl : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";

string name = context.Request["name"];
string password = context.Request["password"];
string c = context.Request["checkdode"];// Receive data from request
string html = File.ReadAllText(context.Server.MapPath("/dl.html"));

if (string.IsNullOrEmpty(name))
{

context.Response.Write(html);
}
else
{

if (c == context.Session["checkdode"].ToString())// Compare the requested data with the stored data
{

if (name == "zhangsan" && password == "lisi")
{

string sql = "select * from cj";
DataTable dt = SqlHelper.ExecuteDataTable(sql, null);
for (int i = 0; i < dt.Rows.Count; i++)
{

context.Response.Write(dt.Rows[i]);

}

}
else
{
html = html.Replace("{meggtuon}", " Wrong password ");
context.Response.Write(html);

}
}
}
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

3. Static templates

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form action="dl.ashx" method="post">
<p> Please enter your account number :<input type="text" name="name" /></p>
<p> Please input a password :<input type="text" name="password" /></p>
<p> Please enter the verification code :<input type="text" name="checkdode" /><img src="/createcheckcode.ashx"/></p>
<p><input type="submit" name="dl" value=" Sign in "/> {meggtuon}
</p>

</form>
</body>
</html>

asp.net Verification Code ( One )Session More articles about

  1. ASP.net Verification Code (C#) MVC

    ASP.net Verification Code (C#) MVC http://blog.163.com/xu_shuhao/blog/static/5257748720101022697309/ Add verification code to the website , Mainly to prevent the machine ...

  2. MVC Validation of the ( A combination of model annotations and non intrusive scripting ) .Net In the middle of the world Redis .net Send email by code Log4net (Log for .net) Use GDI Technology creation ASP.NET Verification Code Razor template engine (RazorEngine) .Net Regular expressions that programmers should master

    MVC Validation of the ( A combination of model annotations and non intrusive scripting )   @HtmlHrlper Tags created in this way , Some properties will be generated automatically , Some of these properties are about validation As shown in the figure : Model annotations After model annotation ,MVC Validation of the , Including front desk guests ...

  3. ASP.NET Medium Session How to use it correctly

    Session Object is used to store access from a user to a specific aspx From the page of , Until the user leaves , Information needed for a particular user session . When users switch pages in the application ,Session Object variables are not cleared .  For one Web application ...

  4. ASP.NET Inside Session Explain in detail

    Session Model introduction Session What is it? ? In short, it is a number given by the server to the client . When one WWW Server runtime , There may be several users browsing the website running on this server . When each user first interacts with this WWW The server establishes a connection ...

  5. ASP.NET Medium Session How to use it correctly [ turn ]

    Session Object is used to store access from a user to a specific aspx From the page of , Until the user leaves , Information needed for a particular user session . When users switch pages in the application ,Session Object variables are not cleared .  For one Web application ...

  6. PHP+jQuery One of the improvements to the registration module : The verification code is stored SESSION

    /* ******* Date:2014-09-28 ******* Author: Small dee ******* Blog:http://www.cnblogs.com/dee0912/*/ For the last post ...

  7. ASP.NET conversation (Session) Save mode -- Finally know session Why is it lost

    [ original ]ASP.NET conversation (Session) Save mode author : Cold feather Maple (cityhunter172) Hello everyone , I haven't written anything for more than four months . Let's talk about it today Session stay .Net v1.0/v1.1 in ...

  8. 【 turn 】asp.net In the use of session Object delivery 、 Shared data [session usage ]

    come from :http://blog.unvs.cn/archives/session-transfer-method.html Let's introduce Asp.net In the use of session Object delivery . Shared data usage : 1. Transfer value ...

  9. 【 translation 】 A talk ASP.NET Medium Session

    In recent two days, a Web Farm In the environment Session It's very painful to deal with the problem , Looking for solutions on the Internet , I read this article by accident , I feel very good , I checked , There seems to be no ready-made translation , So I translated this article with my teeth and feet ...

Random recommendation

  1. stay Oracle Linux Server release 6.4 The configuration ocfs2 file system

    ① install ocfs-tools-1.8 If using RedHat Enterprise Linux 6.4, You can also install ocfs-tools-1.8 Of , Just to insert Oracle Linux Server re ...

  2. java_ Array as immutable class instance of cache pool

    package ming; public class CacheImmutale { private static int MAX_SIZE = 10; private static CacheImm ...

  3. js Replication of objects , Pass on , newly added , Delete and compare

    When we copy or pass an object to a function , It's often a reference to the object that's passed . So any changes we make to the references , Will affect the original object it refers to .  Copy , Copy   var o = { add: 'Changdao ...

  4. Could Not Connect

    In writing today Quartz Timing task web When applied , The access project page appears Could Not Connect, Backstage didn't make a mistake . Then I visit http://127.0.0.1:8080(Apache Home page ) It's normal when you're on the road . ...

  5. Neo4j Chapter five : Batch update data

    Compared to the query of graphic data ,Neo4j Updating graphics data is slow , Usually ,Neo4j The workflow for updating data is : Each data update will perform a database connection , Open a transaction , Updating data in a transaction . When the amount of data is very large , It's very time-consuming ...

  6. Sync blog —CSDN Extension

    niiickのCSDN use CSDN It's been a few months In fact, at the beginning, someone asked me to go to the blog Garden, but I refused ( After all, obsessive-compulsive disorder can't be accepted. One blog is only half = =) But recently I had the honor to see someone dalao Blog garden It's great to find no ads !!! set up ...

  7. PostgreSQL Sort Chinese characters by pinyin

    from :https://www.cnblogs.com/gaojian/p/3188609.html postgres=# \l List of databases Name | Owner | Enc ...

  8. JavaScript first

    Warning alert() confirm confirm() put questions to prompt() Space JavaScript- Open a new window (window.open) open()  Method to find an existing or new browser window . grammar : ...

  9. SQL Optimize the index of actual combat

    A friend told me that in his virtual machine mysql Can't run sql, But in the local environment it's this sql You can run out of it . The first reaction to this problem is : Deadlock . So he asked him to query several states of the database : I found that there were very few instant locks , It's not about the lock . further ...

  10. T4 Study - 4、Kalman Studio-T4 Code generator

    Open source code generator -Kalman Studio https://github.com/loamen/Kalman.Studio The main functions of the software are as follows : 1. be based on T4 Code generation tools for , Generate code according to database metadata information ...