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;
}
} }
Attach
/FastFeedBack.ashx  【处理页面】
<%@ 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-黑色简洁验证码的更多相关文章

  1. 在ashx文件中制作验证码(使用session要继承IRequiresSessionState)

    必须继承System.Web.SessionState.IRequiresSessionState接口,才能实现Session读写! System.Web.SessionState的一些接口 IRea ...

  2. form组件注册ajax登录auth认证及验证码

    本项目采用django自带的数据库 项目文件 models.py from django.db import models from django.contrib.auth.models import ...

  3. aspx与ashx

    ashx在VS的中文版是新建“一般处理程序”,其实是一个实现类System.Web.IHttpHandler接口的类.而任何一个实现了IHttpHandler接口的类都能作为一个外部请求的目标程序.H ...

  4. Asp.Net验证码1

    验证码html调用 验证码:<input name="> <img src="CodeHandler.ashx" id="imgCode&qu ...

  5. ashx一般处理程序和HttpHandler

    asp.net项目中,使用.ashx的文件(一般处理程序)可以用于处理客户端发送来的请求,并将服务器端的处理结果返回给客户端.它能返回的类型可以是文本.或者图片.有时候,我们可以在项目中使用.cs的文 ...

  6. MVC之图片验证码

    MVC之图片验证码 controller中的action方法public ActionResult GetValidateCode() { ValidateCode vCode = new Valid ...

  7. asp.net 一般处理程序实现网站验证码

    使用VerifyCode.ashx一般处理程序生成验证码,实现如下: using System; using System.Drawing; using System.Web; using Syste ...

  8. ashx文件和aspx

    ashx文件和aspx文件有什么不同? 我们先新建一个ashx文件看看: <%@ WebHandler Language="C#" Class="Handler&q ...

  9. 【转载】Asp.Net生成图片验证码工具类

    在Asp.Net应用程序中,很多时候登陆页面以及其他安全重要操作的页面需要输入验证码,本文提供一个生成验证码图片的工具类,该工具类通过随机数生成验证码文本后,再通过C#中的图片处理类位图类,字体类,一 ...

随机推荐

  1. 深入浅出ES6(七):箭头函数 Arrow Functions

    作者 Jason Orendorff  github主页  https://github.com/jorendorff 箭头符号在JavaScript诞生时就已经存在,当初第一个JavaScript教 ...

  2. ***iOS 项目的目录结构能看出你的开发经验

    最近有师弟去面试iOS开发,他谈论到,面试官竟然问他怎么分目录结构的,而且还具体问到每个子目录的文件名. 目录结构确实很重要,面试官问他这些无疑是想窥探他的开发经验.清晰的目录结构,可让人一眼知道对应 ...

  3. hdu 4696 Answers

    思路:由于c[i]要么是1,要么是2.所以当c[i]中没有1的时候就不可能得到奇数: 再就是如果m<=0,也不可能得到. 代码如下: #include<cstdio> #includ ...

  4. 解决 Ubuntu 开机 Waiting for 60 seconds more for network configuration

    sudo vim /etc/network/interfaces, 将该文件的内容修改为如下:(也就是说删掉其他的什么auto eth0.auto wlan0) auto lo iface lo in ...

  5. lintcode :Segmemt Tree Build II

    题目 Segmemt Tree Build II The structure of Segment Tree is a binary tree which each node has two attr ...

  6. 专家谈国产CPU最新发展态势:需强化标准建设(很全面)

    一.国产CPU发展现状与成就 国内已开启多技术路线并行的CPU技术产业新格局.在国家科技重大专项和国家级集成电路产业投资资金的推动之下,我国CPU产品技术研发已进入多技术路线同步推进的高速发展阶段,并 ...

  7. 纯后台生成highcharts图片有哪些方法?

    比如说,领导抛给你一个需求,把一些数据做成图表,每天通过邮件发送,让领导能在邮件中就看到图片,你会有什么思路呢?本人使用的是phantomjs这个神器,它的内核是WebKit引擎,不提供图形界面,只能 ...

  8. Java API —— JDK5新特性

    JDK5新特性         自动拆装箱.泛型.增强for.静态导入.可变参数.枚举   1.增强for概述         1)简化数组和Collection集合的遍历         2)格式: ...

  9. Hibernate检索方式 分类: SSH框架 2015-07-10 22:10 4人阅读 评论(0) 收藏

    我们在项目应用中对数据进行最多的操作就是查询,数据的查询在所有ORM框架中也占有极其重要的地位.那么,如何利用Hibernate查询数据呢?Hibernate为我们提供了多种数据查询的方式,又称为Hi ...

  10. Uboot 2014.07 makefile分析 - 其他Cortex系列

    uboot的官网可以通过谷歌搜索得到,显示结果第一个链接就是. 官网:: http://www.denx.de/wiki/U-Boot ftp下载: ftp://ftp.denx.de/pub/u-b ...