fileuplaod コントロールを使用して画像をアップロードしています。このために、以前はキャッシュに保存していました
バイト形式で 2 時間表示し、.ashx ファイルの HttpContext を使用してこの画像を表示します。何らかの理由でそれ
キャッシュに保存される場合と保存されない場合があります。asp.net 2.0 と C# 言語を使用しています。
保存するための私のコード:
//Name of the Image
string strGuid = Guid.NewGuid().ToString();
byte[] byteImage = new byte[ImageUpload.PostedFile.ContentLength];
//file upload control ID "ImageUpload" and read it and save it in cache.
ImageUpload.PostedFile.InputStream.Read(byteImage, 0, byteImage.Length);
//Saving Byte in the cache
Cache.Add(strGuid, byteImage, null, DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
//Saving Image Format in cache
Cache.Add(string.Format("{0}_Type", strGuid), strContentType, null, DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
UserImage.ImageUrl = string.Format("~/UserControl/ImageHander.ashx?imgId={0}", strGuid);
.ashx ファイルを使用してイメージをレンダリングするためのコード:
public void ProcessRequest (HttpContext context)
{
string strImageGuid = context.Request.QueryString["imgId"].ToString();
string strContentTypeID = string.Format("{0}_Type", context.Request.QueryString["imgId"].ToString());
byte[] byteImage =(byte []) context.Cache[strImageGuid];
string strContentType = (string)context.Cache[strContentTypeID];
context.Response.ContentType = strContentType;
context.Response.OutputStream.Write(byteImage, 0, byteImage.Length);
}
バイトイメージをキャッシュに保存する際に問題はありますか、またはこれを行うための他のより良い方法はありますか?
ありがとう!サンジェイ・パル