自己写的验证码类,在 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"/>
(生成验证码图片及HTML文本:> <img id="VerifyCode1" onclick="this.src=verify.msgx?asd='+Math.random()"
检查IIS设置,启用父路径 这一项我早做了的. 我怀疑是设置的问题,当我把 <add verb="*" path="*.msgx" type="WebUtility.WebControls.VerifyCodeHttpHander"/>
改成
<add verb="*" path="*.aspx" type="WebUtility.WebControls.VerifyCodeHttpHander"/>
就可以显示了,只是所有的.aspx 页都变成了验证码图片
//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
}
http://blog.csdn.net/jy5212/archive/2010/07/09/5722720.aspx
我觉的产生问题的原因类似于UrlReweite到iis7下产生的404错误,更改一下webconfig的配置就可以了
<handlers>
<add name="msgx" path="*.msgx" verb="*" modules="IsapiModule" resourceType="Unspecified" />
</handlers>
</system.webServer>
扯蛋, 我调试时是通的 (估计调试时VS 2008 用的是自带的IIS)