ashx-auth-黑色简洁验证码
| ylbtech-util: ashx-auth-黑色简洁验证码 |
ashx-auth-黑色简洁验证码
| 1.A,效果图返回顶部 |

| 1.B,源代码返回顶部 |
/ImageUniqueCode.ashx
<%@ WebHandler Language="C#" Class="ImageUniqueCode" %> using System;
using System.Web;
using System.Drawing;
using System.Text; public class ImageUniqueCode : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{ public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/gif";
//建立Bitmap对象,绘图
Bitmap basemap = new Bitmap(, );
Graphics graph = Graphics.FromImage(basemap);
graph.FillRectangle(new SolidBrush(Color.White), , , , );
Font font = new Font(FontFamily.GenericSerif, , FontStyle.Bold, GraphicsUnit.Pixel);
Random r = new Random();
string letters = "ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789";
string letter;
StringBuilder s = new StringBuilder(); //添加随机字符
for (int x = ; x < ; x++)
{
letter = letters.Substring(r.Next(, letters.Length - ), );
s.Append(letter);
graph.DrawString(letter, font, new SolidBrush(Color.Black), x * , r.Next(, ));
} //混淆背景
Pen linePen = new Pen(new SolidBrush(Color.Black), );
for (int x = ; x < ; x++)
graph.DrawLine(linePen, new Point(r.Next(, ), r.Next(, )), new Point(r.Next(, ), r.Next(, ))); //将图片保存到输出流中
basemap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
context.Session["ImageUniqueCode"] = s.ToString();
context.Response.End();
} public bool IsReusable {
get {
return true;
}
} }
<%@ WebHandler Language="C#" Class="FastFeedback" %> using System;
using System.Web; public class FastFeedback : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
//最终状态
public enum FeedbackState
{
UniqueCodeError = ,
Succeed = ,
Error = ,
Null =
} public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.CacheControl = "no-cache"; //清空缓存 string code = context.Request["SecurityCode"];
string message = context.Request["Message"]; if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(message))
{
context.Response.Write(FeedbackState.Null.ToString());
context.Response.End();
return;
} try
{
if (code.ToUpper() == context.Session["ImageUniqueCode"].ToString())
{
//执行成功,完成其他任务
//....do.....
context.Response.Write(FeedbackState.Succeed.ToString()); }
else
{
context.Response.Write(FeedbackState.UniqueCodeError.ToString()); }
}
catch (Exception ex)
{
context.Response.Write(FeedbackState.Error.ToString());
}
finally
{
context.Response.End();
}
} public bool IsReusable {
get {
return false;
}
} }
| 1.C,下载地址返回顶部 |
![]() |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
ashx-auth-黑色简洁验证码的更多相关文章
- 在ashx文件中制作验证码(使用session要继承IRequiresSessionState)
必须继承System.Web.SessionState.IRequiresSessionState接口,才能实现Session读写! System.Web.SessionState的一些接口 IRea ...
- form组件注册ajax登录auth认证及验证码
本项目采用django自带的数据库 项目文件 models.py from django.db import models from django.contrib.auth.models import ...
- aspx与ashx
ashx在VS的中文版是新建“一般处理程序”,其实是一个实现类System.Web.IHttpHandler接口的类.而任何一个实现了IHttpHandler接口的类都能作为一个外部请求的目标程序.H ...
- Asp.Net验证码1
验证码html调用 验证码:<input name="> <img src="CodeHandler.ashx" id="imgCode&qu ...
- ashx一般处理程序和HttpHandler
asp.net项目中,使用.ashx的文件(一般处理程序)可以用于处理客户端发送来的请求,并将服务器端的处理结果返回给客户端.它能返回的类型可以是文本.或者图片.有时候,我们可以在项目中使用.cs的文 ...
- MVC之图片验证码
MVC之图片验证码 controller中的action方法public ActionResult GetValidateCode() { ValidateCode vCode = new Valid ...
- asp.net 一般处理程序实现网站验证码
使用VerifyCode.ashx一般处理程序生成验证码,实现如下: using System; using System.Drawing; using System.Web; using Syste ...
- ashx文件和aspx
ashx文件和aspx文件有什么不同? 我们先新建一个ashx文件看看: <%@ WebHandler Language="C#" Class="Handler&q ...
- 【转载】Asp.Net生成图片验证码工具类
在Asp.Net应用程序中,很多时候登陆页面以及其他安全重要操作的页面需要输入验证码,本文提供一个生成验证码图片的工具类,该工具类通过随机数生成验证码文本后,再通过C#中的图片处理类位图类,字体类,一 ...
随机推荐
- 1051 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [wikioi]线段树练习 2
http://codevs.cn/problem/1081/ #include <vector> #include <iostream> #include <string ...
- JavaWeb项目开发案例精粹-第3章在线考试系统-002配置文件及辅助类
1. <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5&qu ...
- 223. Rectangle Area
题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...
- javascript grunt安装和使用
grunt是javascript世界的构建工具. 为何要用构建工具? 一句话:自动化.对于需要反复重复的任务,例如压缩(minification).编译.单元测试.linting等.自动化工具可以减轻 ...
- python生成验证码脚本
最近每天都用python写一个小的脚本,练习使用python语法. 验证码的生成: 这里使用了python的图像处理库PIL,安装PIL的过程中出了一个小麻烦,就使用Pillow-win32的一个文件 ...
- IOS地图及定位使用
1.定位 定位使用CoreLocation库,引入CoreLocation/CoreLocation.创建CLLocationManager对象,使用startUpdatingLocation方法开始 ...
- 25-语言入门-25-n-1位数
题目地址: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=96 描述已知w是一个大于10但不大于1000000的无符号整数,若w是n(n ...
- UIColor的用法
UIColor,CGColor,CIColor的区别和联系 layer.shadowColor = [UIColor redColor].CGColor; 这个是今天用到的.顺便总结一下. 1.UIC ...
- jQuery EasyUI - Add link to datagrid cell
Extracted from: http://stackoverflow.com/questions/16061894/jquery-easyui-add-link-to-cell HTML: < ...
