HttpContext に保存するアイテムがあります。
HttpContext.Current.Items["myItem"] = "123";
ページのどのメソッドからでも問題なくアクセスできます。例えば:
protected override void OnLoad(EventArgs e)
{
string l_myItemVal = HttpContext.Current.Items["myItem"] as string; // "123"
}
これはうまくいきます。
ただし、AJAX を介してページの Web メソッドの 1 つを呼び出すと、これは失敗します。
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string MyWebMethod()
{
string l_myItemVal = HttpContext.Current.Items["myItem"] as string; // NULL
}
非同期呼び出しの HttpContext は、ページの HttpContext とは異なりますか?