62,074
社区成员
发帖
与我相关
我的任务
分享
自己写的验证码类,在 Windows Server 2003(iis 6) 下正常, 在 Win 7 (IIS 7)下无法显示,
我觉得应该配置的问题,却好久未得正解. 特请各位指点~~~
类全名: WebUtility.WebControls.VerifyCode
HttpHander全名: WebUtility.WebControls.VerifyCodeHttpHander
(生成验证码图片及HTML文本:>
<img id="VerifyCode1" onclick="this.src='msgx.aspx?asd='+Math.random()" src="verify.msgx" alt="点击刷新" style="cursor:pointer;vertical-align:middle;" /> )
web.config 配置: system.web 下 httpHandlers 下
<add verb="*" path="*.msgx" type="WebUtility.WebControls.VerifyCodeHttpHander"/>
检查IIS设置,启用父路径 这一项我早做了的.
我怀疑是设置的问题,当我把
<add verb="*" path="*.msgx" type="WebUtility.WebControls.VerifyCodeHttpHander"/>
改成
<add verb="*" path="*.aspx" type="WebUtility.WebControls.VerifyCodeHttpHander"/>
就可以显示了,只是所有的.aspx 页都变成了验证码图片
我逐一按各位的意思去做了的。全都无济于事~~。不知为何 哎~~~~~~~~
<system.webServer>
<handlers>
<add name="msgx" path="*.msgx" verb="*" modules="IsapiModule" resourceType="Unspecified" />
</handlers>
</system.webServer>
//Hander 内容如下
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));// 使用Cookies取验证码的值
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
}