HttpHandlerFactory来根据不同的后缀名调用不通的图片生成Handler来生成图片
//有点类似简单工厂设计模式, 类似DBFactory。
//web.configusing System;
using System.Data;
using System.Configuration;
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;
public class ImageHandler:IHttpHandlerFactory
{
public ImageHandler()
{
}
#region IHttpHandlerFactory Members
IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
string imgType = context.Request.QueryString["ext"];
if (string.IsNullOrEmpty(imgType))
imgType = "jpg";
imgType = imgType.ToLower();
if (imgType == "jpg")
return new JpgHandler();
else
return new GifHandler();
}
void IHttpHandlerFactory.ReleaseHandler(IHttpHandler handler)
{
}
#endregion
}
using System.Data;
using System.Configuration;
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;
public class ImageHandler:IHttpHandlerFactory
{
public ImageHandler()
{
}
#region IHttpHandlerFactory Members
IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
string imgType = context.Request.QueryString["ext"];
if (string.IsNullOrEmpty(imgType))
imgType = "jpg";
imgType = imgType.ToLower();
if (imgType == "jpg")
return new JpgHandler();
else
return new GifHandler();
}
void IHttpHandlerFactory.ReleaseHandler(IHttpHandler handler)
{
}
#endregion
}
<httpHandlers>
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true" />
<add verb="*" path="*" type="ImageHandler"/>
</httpHandlers>
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true" />
<add verb="*" path="*" type="ImageHandler"/>
</httpHandlers>