【原】在一般处理程序中设置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(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;

            }

        }

    }

}

 

你可能感兴趣的:(session)