aspnet 2.0ページディレクティブで出力キャッシュパラメータを使用する際に問題があります。私は選択された画像の値を保持するためにセッション変数を使用しています。ページディレクティブで出力キャッシュがtrueに設定されていると、データリストの動的制御が機能していないようです。ページディレクティブを使わないようにイメージを別々にキャッシュする方法はありますか?SQl Server 2005データベースコールからイメージをキャッシュする方法は?
データリストコード
"RepeatColumns =" 6" CellPadding作業= "8" CELLSPACING = "8" グリッド線= "両方" SelectedItemStyle-のBackColor = "#1 33ff66" OnSelectedIndexChanged = "dtlImages_SelectedIndexChanged" OnItemCommand = "dtlImages_ItemCommand"> 'にrunat = "サーバー">
' ID = "lblDescription" フォント・太字= "真" のfont-size = "12ピクセル" フォント名= "Arialの">
データベースから画像を検索
コード
保護されたボイドをPage_Load(オブジェクト送信者、System.EventArgs e)の {列= strImageID場合、Request.QueryString [ "ID"]。
string wf4uConnect = System.Configuration.ConfigurationManager.ConnectionStrings["wf4uConnectionString"].ConnectionString;
System.Data.SqlClient.SqlConnection wf4uConn = new System.Data.SqlClient.SqlConnection(wf4uConnect);
System.Data.SqlClient.SqlCommand myCommand = new SqlCommand("Select ImageFile, ImageType from wf4u_ImageThumb Where ImageId =" + strImageID, wf4uConn);
wf4uConn.Open();
SqlDataReader byteReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while ((byteReader.Read()))
{
Response.BinaryWrite((byte [])byteReader.GetValue(0));
Response.ContentType = (string)byteReader.GetValue(1);
}
wf4uConn.Close();
}
ウェブページに読み込まれるときに画像をキャッシュするためのHTTPコンテキストオブジェクトを実装しました。
public ImageList(string clientName) { HttpContext context = HttpContext.Current;
if((context.Cache["ImageIdList" + clientName] == null))
{
string wf4uConnect = System.Configuration.ConfigurationManager.ConnectionStrings["wf4uConnectionString"].ConnectionString;
System.Data.SqlClient.SqlConnection wf4uConn = new System.Data.SqlClient.SqlConnection(wf4uConnect);
string queryStr = "SELECT ImageId FROM wf4u_imageThumb WHERE ClientName = @ClientName";
SqlCommand ImageIdComm = new System.Data.SqlClient.SqlCommand(queryStr, wf4uConn);
ImageIdComm.Parameters.Add("@ClientName", SqlDbType.VarChar).Value = clientName;
wf4uConn.Open();
SqlDataReader ImageIdReader = ImageIdComm.ExecuteReader();
if (ImageIdReader.Read())
{
_ImageId = ImageIdReader.GetInt32(0);
_ClientName = ImageIdReader.GetString(1);
context.Cache.Insert("ImageIdList" + clientName, this, null, DateTime.Now.AddSeconds(600), TimeSpan.Zero);
}
wf4uConn.Close();
}
else
{
ImageList list = (ImageList)context.Cache["ImageIdList" + clientName];
_ImageId = list.ImageId;
_ClientName = list.ClientName;
}
}
いずれの提案も歓迎されます。
RJ:問題に関連するコードを投稿できますか?おそらく出力ディレクティブ、データリスト、バインディングコード、Sessionオブジェクトへの保存? –
これは私の最初の質問です。追加コードを投稿すると少し失われてしまいます。このコメントセクションは600文字に制限されています。コメントに投稿を追加するにはどうすればよいですか?私はここの豚のように感じるので、私はそのフラックを取ると思う。 – rjsteward
最も簡単な方法は、質問を編集し、コメントの関連部分を引用することです。 – devstuff