我正在寻找创建一个处理程序来返回基于传递的id的图像,我没有创建自己的一个之前和当我创建它时它提到它必须在IIS注册.这个项目分发给很多客户,我是否需要更改每个客户端的IIS或者是否有某种方式来处理这个或处理器的替代方案?
编辑:响应下面,这是我创建(但尚未测试),所以我需要更改IIS或web.config中的任何内容吗?
public class Photos : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
//write your handler implementation here.
var img = Image.FromFile(@"C:\Projects\etc\logo.jpg");
context.Response.ContentType = "image/jpeg";
img.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
#endregion
}
Run Code Online (Sandbox Code Playgroud)
您可以创建一个继承的类,IHttpHandler并在其中获取id(来自查询字符串或类似字符串),处理请求并返回二进制数据.不应该用IIS注册它...
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Get Id from somewhere
//Get binary data
context.Response.ContentType = "application/octet-stream";
context.Response.BinaryWrite(bytes);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5605 次 |
| 最近记录: |