I am using a simple handler to display an image on MVC view, it works great on my localhost but when I publish it to our hosting server I get this error (using Fiddler):
GET ImageHandler.ashx?img=b...w=255&level=128&slice=0 500 Internal Server Error
Here is the view script:
<img id="Image1" alt="image" src="ImageHandler.ashx?img=bmptest.bmp&window=255&level=128&slice=0" height="512" width="512" />
Here is the handler's script:
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string sImageFileName = "";
int slice = 0;
int window = 0;
int level = 0;
sImageFileName = context.Request.QueryString["img"].ToLower().Trim();
.....
System.Drawing.Image objImage = null;
Image bmp = Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("content/" + sImageFileName));
MemoryStream objMemoryStream = new MemoryStream();
bmp.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imageContent = new byte[objMemoryStream.Length];
objMemoryStream.Position = 0;
objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length);
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(imageContent);
}
public bool IsReusable
{
get
{
return false;
}
}
}
I modified web.cong by adding:
<system.web>
......
<httpHandlers>
<add verb="*" path="*.ashx" type="DirectshowTest.ImageHandler,DirectshowTest"/>
</httpHandlers>
</system.web>
Would appreciate your suggestions.
I added the following to Global.asax:
routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
It is working now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.