62,046
社区成员
发帖
与我相关
我的任务
分享
//类VerifyCode的部分成员
public string GetCodeString
{
get
{
//调试总是说,未将对象引用设置到对象的实例
string code = HttpContext.Current.Request.Cookies[VerifyCode.GetCookieKey].Value;
return HttpContext.Current.Server.HtmlDecode(code);
}
}
public static string GetCookieKey
{
get { return "67D2F3EE-A228-4b0e-9F0A-23A58FFD38CE"; }
}
public class VerifyCodeHttpHander : IHttpHandler, IRequiresSessionState
{
#region IHttpHandler 成员
/// <summary>
/// 是否可以处理远程的HTTP请求
/// </summary>
public bool IsReusable
{
get { return true; }
}
/// <summary>
/// 将验证码图片发送给WEB浏览器
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
MemoryStream ms = new MemoryStream();
VerifyCode v = new VerifyCode();
String code = context.Server.HtmlEncode(v.CreateVerifyCode());
Bitmap map = v.CreateImageCode(code);
context.Response.Cookies.Add(new HttpCookie(VerifyCode.GetCookieKey, code));
map.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);//将位图写入内存流
context.Response.ClearContent();//清除缓冲区里的所有内容输出
context.Response.ContentType = "image/jpeg";//需要输出图象信息 要修改HTTP头
context.Response.BinaryWrite(ms.ToArray());//将内存流写入HTTP输出流
map.Dispose();
ms.Close();
ms.Dispose();
context.Response.End();
}
#endregion
}
在 VS2008 里浏览,该自定义控件可以正常显示,但在IIS7里,用 http://localhost:* 访问去打开不.
验证码显示不出来.是怎么回事