0
我想运行我的httphandler,当某个用户访问像png,jpeg,gif和其他扩展名的图像文件时。但是当我尝试路径时,我得到了错误404。我认为什么服务器试图找到磁盘上的文件,但我想使用别名访问我的处理程序中的文件和更新的访问真实物理文件路径。
示例配置文件:在asp.net应用程序中不运行http处理程序
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add verb="GET,HEAD" path="*.jpg" type="Startup.Shop.ImageHandler, Startup.Shop" validate="false"/>
</httpHandlers>
<authorization>
<allow users="*" />
</authorization>
</system.web>
<system.webServer>
<handlers>
<add name="ImageHandlerfor JPG" path="*.jpg" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
<add name="ImageHandler for GIF" path="*.gif" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
<add name="ImageHandler for BMP" path="*.bmp" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
<add name="ImageHandler for PNG" path="*.png" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
</handlers>
</system.webServer>
/configuration>
例处理类:
public class ImageHandler : IHttpHandler, IRouteHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return this;
}
}
等等 - IIS服务器可配置为经典模式
是的,我忘了添加有关设置服务器。在处理程序映射中,有下一个名为ImageHandler的处理程序和设置: 请求路径:* .png,* .jpeg,*。jpg,*。gif 可执行文件:C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ aspnet_isapi .dll, 所有动词和路径类型:未指定 – martmartius
如果这适用于您,您可以标记为已回答吗? – Paul