ashx生成验证码存Session时的需要实现一个标记方法的接口IRquiresSessionState,否则存Session时会报错
using Common;
using System.Web;
using System.Web.SessionState;
namespace WebApp2019ASPX._09Session
{
/// <summary>
/// _04GenerateValidateCode 的摘要说明
/// </summary>
public class _04GenerateValidateCode : IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
//生成验证码图像过程 : ValicateCode实例化-->生成验证码文本--->存到Session中供与输入验证码比对--->文本生成验证码图片让用户参照输入
ValidateCode vc = new ValidateCode();
string strCode= vc.CreateValidateCode(4);
context.Session["validateCodeSession"] = strCode;//供输入时提取与输入比对
vc.CreateValidateGraphic(strCode, context);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

浙公网安备 33010602011771号