我的Session为什么老是为NULL?
开发环境VS2005,想做一个验证码。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
public partial class ValidateCode : System.Web.UI.Page
{
private readonly string ImagePath = "Validator.jpg ";
private string gifNubic = " ";
protected void Page_Load(object sender, EventArgs e)
{
gifNubic = GetRandomint ();
Session[ "test "] = gifNubic;
///创建Bmp位图
Bitmap bitMapImage = new System.Drawing.Bitmap(Server.MapPath(ImagePath));
Graphics graphicImage = Graphics.FromImage(bitMapImage);
///设置画笔的输出模式
graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
///添加文本字符串
graphicImage.DrawString(gifNubic, new Font( "Arial ", 10, FontStyle.Bold), SystemBrushes.WindowText, new Point(0, 0));
///设置图像输出的格式
Response.ContentType = "image/jpeg ";
///保存数据流
bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);
///释放占用的资源
graphicImage.Dispose();
bitMapImage.Dispose();
//Session.Remove(RandomCode);
//Session.Remove( "test ");
}
private String GetRandomint()
{
Random random = new Random();
return (random.Next(10000, 99999).ToString());
}
}
以上是获