日期:2014-05-18  浏览次数:20387 次

如何配置web.config里的httpHandlers
我在~/SysManage/的目录下写了一个UserPictureHandler.ashx,代码如下:
C# code

public class UserPictureHandler : IHttpHandler {

    private const string WaterMarkURL = "~/images/WaterMark.png";
    
    public void ProcessRequest (HttpContext context) {
        Image UserHead = Image.FromFile(context.Request.PhysicalPath);
        Image WaterMark = Image.FromFile(context.Request.MapPath(WaterMarkURL));
        Graphics g = Graphics.FromImage(UserHead);
        g.DrawImage(WaterMark, new Point(UserHead.Width - WaterMark.Width, UserHead.Height - WaterMark.Height));
        g.Dispose();
        WaterMark.Dispose();
        context.Response.ContentType = "image/Gif";
        UserHead.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        UserHead.Dispose();
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}


我在根目录下的web.config里的配置如下:
XML code

<httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    <add verb="*" path="images/Users/*.gif" type="UserPictureHandler"/><!--就是这个配置-->
</httpHandlers>


它报这个错:未能加载类型“UserPictureHandler”。
显示的就是<add verb="*" path="images/Users/*.gif" type="UserPictureHandler"/>这一行
我那个User文件夹是放头像的,我要给它加水印的
这配置应该怎么写????

------解决方案--------------------
type="UserPictureHandler" 指定完整点.namespace.className
------解决方案--------------------
每次打开头加水印,太多余了.
------解决方案--------------------
如果没有指定命名空间则命名空间就是App_Code
App_Code.UserPictureHandler


============================================
国内首个源码搜索引擎[码库]——www.muchool.com
并有本站自主研发的ASP.NET大型开源BLOG系统,欢迎下载
------解决方案--------------------
我以前做的HTTP接口,希望有帮助
path为外部访问地址~/interface.sample?
type为classname,如果有命名空间为namespace.className
XML code

<httpHandlers>
<add path="interface.sample" verb="*" type="UserPictureHandler"/>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
</httpHandlers>