zoukankan      html  css  js  c++  java
  • ASP.NET:在一般处理程序中通过 Session 保存验证码却无法显示图片?

     1 using System.Drawing;
     2 using System.Web;
     3 using System.Web.SessionState;
     4 
     5 /// <summary>
     6 /// CaptchaHandler 的摘要说明
     7 /// </summary>
     8 public class CaptchaHandler : IHttpHandler, IRequiresSessionState  //简记:我需要Session
     9 {
    10 
    11   public void ProcessRequest(HttpContext context)
    12   {
    13 
    14     // GDI+ 三步 1画布 2为画布创建画笔 3绘制所需素材
    15 
    16     var vCode = CaptchaHelper.CreateRandomCode(5);  //自己封装的方法
    17 
    18     var buffer = CaptchaHelper.DrawImage(vCode, background: Color.White);  //自己封装的方法
    19     context.Session["vCode"] = vCode;  //vCode:string 类型的验证码字符串
    20 
    21     context.Response.ContentType = "image/gif";
    22     context.Response.BinaryWrite(buffer);
    23   }
    24 
    25   public bool IsReusable { get { return false; } }
    26 }

    在一般处理程序中如果要使用Session:

    【关键】Handler 要实现 IRequiresSessionState 接口(所在的命名空间 using System.Web.SessionState;)

  • 相关阅读:
    Storyboard里面的几种Segue区别和视图的切换
    2014年12月英语单词
    测试和调试的区别
    黑苹果安装教程(一)
    IOS基础——IOS学习路线图(一)
    遇到Wampserver遇到的问题
    产生不重复的数字
    简单的布局
    2014年8月
    算法小全
  • 原文地址:https://www.cnblogs.com/liqingwen/p/4558547.html
Copyright © 2011-2022 走看看