[英]500 Internal Server Error - handler, asp.net MVC
我正在使用一個簡單的處理程序在MVC視圖上顯示圖像,它在我的本地主機上運行良好,但是當我將其發布到托管服務器時,出現此錯誤(使用Fiddler):
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>
感謝您的建議。
我在Global.asax中添加了以下內容:
routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
現在正在工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.