0
我正在使用一個簡單的處理程序來顯示MVC視圖上的圖像,它在我的本地主機上效果很好,但是當我將它發佈到我們的託管服務器時出現此錯誤(使用Fiddler ):500內部服務器錯誤 - 處理程序,asp.net MVC
GET ImageHandler.ashx?img=b...w=255&level=128&slice=0 500 Internal Server Error
這裏是視圖腳本:
<img id="Image1" alt="image" src="ImageHandler.ashx?img=bmptest.bmp&window=255&level=128&slice=0" height="512" width="512" />
這裏是處理程序的腳本:
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;
}
}
}
我修改了web.cong加入:
<system.web>
......
<httpHandlers>
<add verb="*" path="*.ashx" type="DirectshowTest.ImageHandler,DirectshowTest"/>
</httpHandlers>
</system.web>
希望你的建議。
事件日誌中是否有任何細節? – Fahad