セッションに何らかの値を割り当てている状況があります。そのコードが繰り返し呼び出されている状況があります。時々、このコードはオブジェクト null のエラーをスローします。値を割り当てている間になぜこれが起こっているのかわかりません。私のコードは
if (HttpContext.Current.Cache["Cache"] == null)
{
CreateChanhe();
DataTable dtcache= HttpContext.Current.Cache["HNS Connection"] as DataTable; //CreateConnectString(CCMMUtility.Encryptdata(txtPin.Text));
string sqlFilter = "Sp = '" + classses.DecryptString(HttpContext.Current.Request.Cookies["Cookies"].Values["sp"].ToString(), classses.SP) + "'";
DataRow[] dr = dtcache.Select(sqlFilter);
if (dr.Length > 0)
{
String[] Con = new String[2];
Con[0] = dr[0][0].ToString();
Con[1] = dr[0][1].ToString();
sp= Con[1];
HttpContext.Current.Session["Name"] = dr[0][2].ToString();
}
}
デバッグ中に「ウォッチの追加」を実行しようとすると、「値」には値がありますが、HttpContext.Current.Session["Name"]は null です。なぜこれが起こっているのか教えてください。
実際にキャッシュを作成し、そのキャッシュからセッションを埋めます。これは私の要件に基づいています。