您的位置:首页 > 其它

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

2015-04-26 22:28 288 查看
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(4);
//类要实现System.Web.SessionState.IRequiresSessionState,这个才能设置session,否则会报错;
context.Session["user_vcode"] = code;
var img = CaptchaHelper.DrawImage(code, 20, background: Color.White);
context.Response.ContentType = "image/gif";
context.Response.BinaryWrite(img);

}

public bool IsReusable
{
get
{
return false;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: