我正在使用ashx文件從數據庫中檢索圖像。 如果它在數據庫中不可用,它會顯示在我的 項目文件夾中的另一個圖像。但我無法訪問本地圖像。 任何人都可以幫我或建議一些東西嗎?在asp.net中通過.ashx訪問本地圖像
我的代碼:
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
string Value = (string)context.Session["UserID"];
Stream strm = ShowEmpImage(Value);
if (strm == null)
{
byte[] imageBytes = File.ReadAllBytes("~/images/photo_not_available.png" + context.Request["image"]);
context.Response.ContentType = "image/png";
context.Response.BinaryWrite(imageBytes);
}
else
{
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}
//context.Response.BinaryWrite(buffer);
}
ThnnQ
感謝您的respond.But它顯示像「名‘服務器’的錯誤不存在於當前上下文中「 – 2012-01-27 12:56:00
@SantoshSahu使用context.Responce.TransmitFile調用它不要等待所有事情都由其他人解決,開始思考你的代碼。 – Aristos 2012-01-27 13:00:27
感謝您的好解決方案。 – 2017-01-24 16:47:28