誰かが私が次の問題の解決策を見つけるのを手伝ってくれますか?
ASP.NET Webサイトの場合:Application_OnPostAuthenticate()イベントで、私が記述したコードはすべて、要求ごとに実行されます。したがって、このcustomidentityオブジェクトにより、countryidとweatheridは、リクエストごとに毎回呼び出されます(値についてはデータベースを呼び出します)。ページの応答時間や不要なコード実行に影響します。
void Application_OnPostAuthenticateRequest(object sender、EventArgs e){
// Get a reference to the current User IPrincipal objIPrincipal = HttpContext.Current.User; // If we are dealing with an authenticated forms authentication request if ((objIPrincipal.Identity.IsAuthenticated) && (objIPrincipal.Identity.AuthenticationType == "Forms")) { CustomPrincipal objCustomPrincipal = new CustomPrincipal(); objCustomPrincipal = objCustomPrincipal.GetCustomPrincipalObject(objIPrincipal.Identity.Name); HttpContext.Current.User = objCustomPrincipal; CustomIdentity ci = (CustomIdentity)objCustomPrincipal.Identity; HttpContext.Current.Cache["CountryID"] = FatchMasterInfo.GetCountryID(ci.CultureId); HttpContext.Current.Cache["WeatherLocationID"] = FatchMasterInfo.GetWeatherLocationId(ci.UserId); Thread.CurrentPrincipal = objCustomPrincipal; }
}
次のようにコードを変更しようとしたときにこの問題を解決するにはHttpContext.Current.Session.Add( "test"、FatchMasterInfo.GetWeatherLocationId(ci.UserId);); キャッシュの代わりに、「オブジェクト参照がオブジェクトのインスタンスに設定されていません」という次のエラーが見つかりました
Application_OnPostAuthenticate()イベント内にセッション変数を格納できるかどうかわかりませんか?