【原】在一般处理程序中设置session

时间:2023-03-09 16:23:39
【原】在一般处理程序中设置session
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web; namespace Itcast.Mall.WebApp.Handlers
{
/// <summary>
/// Vcode 的摘要说明
/// </summary>
public class Vcode : IHttpHandler,System.Web.SessionState.IRequiresSessionState
{ public void ProcessRequest(HttpContext context)
{
var code = CaptchaHelper.CreateRandomCode();
//类要实现System.Web.SessionState.IRequiresSessionState,这个才能设置session,否则会报错;
context.Session["user_vcode"] = code;
var img = CaptchaHelper.DrawImage(code, , background: Color.White);
context.Response.ContentType = "image/gif";
context.Response.BinaryWrite(img); } public bool IsReusable
{
get
{
return false;
}
}
}
}