長期以來流錄入數據庫的圖片現在就涉及到我的本地計算機上錄入數據庫圖像的Web應用程序項目時,我已經發現了一些惱人的。就本地而言,我的意思是這是在我的工作站上使用VS 2008和SQL Server 2005的典型環境。每當我使用HttpHandler在本地顯示圖像時,只有一些圖像在每個頁面上呈現。使用的HttpHandler
然而,當我推應用程序託管環境中,問題通常會消失。但是,我只是將一個新項目推送到託管環境,並遇到了與本地相同的問題 - 這次該站點和數據庫位於託管環境中的同一臺服務器上。有沒有人知道這裏發生了什麼?
這裏的處理程序:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class FeaturedHandler : IHttpHandler
{
Business biz = new Business();
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["ListingID"] != null)
{
int listingID = Convert.ToInt32(context.Request.QueryString["ListingID"]);
DataSet ds = biz.GetFeaturedImageByID(listingID);
DataRow row = ds.Tables[0].Rows[0];
byte[] featureImage = (byte[])row["Photo"];
context.Response.ContentType = "image/jpeg";
context.Response.OutputStream.Write(featureImage, 0, featureImage.Length);
}
else
throw new ArgumentException("No ListingID parameter specified");
}
public bool IsReusable
{
get
{
return false;
}
}
}
我一直在使用一個單獨的服務器上的數據庫嘗試,但遇到同樣的問題。我應該使用DataReader嗎?
UPDATE 因爲我正在讀取二進制數據,所以最初我應該使用DataReader。
可能相關:http://stackoverflow.com/questions/5500950/what-is-the-use-for-ihttphandler-isreusable – 2011-03-31 17:24:08