/// <summary>セッションを消去</summary> /// <remarks>併せてSessionタイムアウト検出用Cookieを消去</remarks> protected void FxSessionAbandon() { // セッションタイムアウト検出用Cookieを消去 FxCmnFunction.DeleteCookieForSessionTimeoutDetection(); // セッションを消去 MyHttpContext.Current.Session.Clear(); }
/// <summary>セッションを消去</summary> /// <remarks>併せてSessionタイムアウト検出用Cookieを消去</remarks> protected void FxSessionAbandon() { // セッションタイムアウト検出用Cookieを消去 Response.Cookies.Set(FxCmnFunction.DeleteCookieForSessionTimeoutDetection()); // セッションを消去 Session.Abandon(); }
/// <summary>セッションを消去</summary> /// <remarks>併せてSessionタイムアウト検出用Cookieを消去</remarks> protected void FxSessionAbandon() { // Set-Cookie HTTPヘッダをレスポンス Response.Cookies.Set(FxCmnFunction.DeleteCookieForSessionTimeoutDetection()); // セッションを消去 Session.Abandon(); }
public IActionResult Index() { ISession session = MyHttpContext.Current.Session; int? flg = session.GetInt32(FxHttpContextIndex.SESSION_ABANDON_FLAG); if (flg.HasValue) { if (Convert.ToBoolean(flg.Value)) { // セッション タイムアウト検出用Cookieを消去 // ※ Removeが正常に動作しないため、値を空文字に設定 = 消去とする // Set-Cookie HTTPヘッダをレスポンス FxCmnFunction.DeleteCookieForSessionTimeoutDetection(); try { // セッションを消去 session.Clear(); } catch (Exception ex) { // エラー発生時 // このカバレージを通過する場合、 // おそらく起動した画面のパスが間違っている。 Console.WriteLine("このカバレージを通過する場合、おそらく起動した画面のパスが間違っている。"); Console.WriteLine(ex.Message); } } } return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); }
/// <summary> /// 画面起動時に実行されるイベントハンドラ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { //画面にエラーメッセージ・エラー情報を表示する----------------------------- //エラーメッセージをHTTPコンテキストから取得 string err_msg = (string)HttpContext.Current.Items[FxHttpContextIndex.SYSTEM_EXCEPTION_MESSAGE]; //エラー情報をHTTPコンテキストから取得 string err_info = (string)HttpContext.Current.Items[FxHttpContextIndex.SYSTEM_EXCEPTION_INFORMATION]; //画面にエラーメッセージを表示する this.Label1.Text = CustomEncode.HtmlEncode(err_msg); //画面にエラー情報を表示する this.Label2.Text = CustomEncode.HtmlEncode(err_info); // ------------------------------------------------------------------------ //画面にフォーム情報を表示する--------------------------------------------- //HTTPリクエスト フォーム情報 HttpRequest req = HttpContext.Current.Request; //コレクション System.Collections.Specialized.NameValueCollection froms = req.Form; if (froms != null) { //foreach foreach (string strKey in froms) { if (froms[strKey] == null) { al_form.Add(new PositionData(strKey, "null")); } else { al_form.Add(new PositionData(strKey, CustomEncode.HtmlEncode(froms[strKey].ToString()))); } } //データバインド this.Repeater1.DataSource = al_form; this.Repeater1.DataBind(); } // ------------------------------------------------------------------------ // 画面にセッション情報を表示する------------------------------------------ //HTTPセッション情報 System.Web.SessionState.HttpSessionState sess = HttpContext.Current.Session; if (sess != null) { //foreach foreach (string strKey in sess) { if (sess[strKey] == null) { al_session.Add(new PositionData(strKey, "null")); } else { al_session.Add(new PositionData(strKey, CustomEncode.HtmlEncode(sess[strKey].ToString()))); } } //データバインド this.Repeater2.DataSource = al_session; this.Repeater2.DataBind(); } // ------------------------------------------------------------------------ // セッション情報を削除する------------------------------------------------ if ((bool)HttpContext.Current.Items[FxHttpContextIndex.SESSION_ABANDON_FLAG]) { // 2009/09/18-start // セッション タイムアウト検出用Cookieを消去 // ※ Removeが正常に動作しないため、値を空文字に設定 = 消去とする // Set-Cookie HTTPヘッダをレスポンス Response.Cookies.Set(FxCmnFunction.DeleteCookieForSessionTimeoutDetection()); // 2009/09/18-end try { // セッションを消去 Session.Abandon(); } catch (Exception ex2) { // エラー発生時 // このカバレージを通過する場合、 // おそらく起動した画面のパスが間違っている。 Console.WriteLine("このカバレージを通過する場合、おそらく起動した画面のパスが間違っている。"); Console.WriteLine(ex2.Message); } } }
///// <summary> ///// アクション メソッドの呼び出し前に呼び出されます。 ///// Controller.OnActionExecuting メソッド (Microsoft.AspNetCore.Mvc) ///// https://docs.microsoft.com/ja-jp/dotnet/api/microsoft.aspnetcore.mvc.controller.onactionexecuting ///// </summary> ///// <param name="filterContext"> ///// 型: Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext ///// 現在の要求およびアクションに関する情報。 ///// </param> //public override void OnActionExecuting(ActionExecutingContext filterContext) //{ // // OnActionExecutionAsyncに移行 //} ///// <summary> ///// アクション メソッドの呼び出し後に呼び出されます。 ///// Controller.OnActionExecuted メソッド (Microsoft.AspNetCore.Mvc) ///// https://docs.microsoft.com/ja-jp/dotnet/api/microsoft.aspnetcore.mvc.controller.onActionexecuted ///// </summary> ///// <param name="filterContext"> ///// 型: Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext ///// 現在の要求およびアクションに関する情報。 ///// </param> //public override void OnActionExecuted(ActionExecutedContext filterContext) //{ // // OnActionExecutionAsyncに移行 //} /// <summary> /// Controller.OnActionExecutionAsync メソッド (Microsoft.AspNetCore.Mvc) /// https://docs.microsoft.com/ja-jp/dotnet/api/microsoft.aspnetcore.mvc.controller.onactionexecutionasync /// </summary> /// <param name="context">Filters.ActionExecutedContext</param> /// <param name="next">ActionExecutionDelegate</param> /// <returns>Task</returns> public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { #region OnActionExecuted に相当する処理 // セッションタイムアウト検出処理 // セッションタイムアウト検出処理の定義を取得 string sessionTimeOutCheck = GetConfigParameter.GetConfigValue(FxLiteral.SESSION_TIMEOUT_CHECK); // デフォルト値対策:設定なし(null)の場合の扱いを決定 if (sessionTimeOutCheck == null) { // OFF扱い sessionTimeOutCheck = FxLiteral.OFF; } // ON / OFF if (sessionTimeOutCheck.ToUpper() == FxLiteral.ON) { // セッションタイムアウト検出処理(ON) // セッション状態の確認 if (MyHttpContext.Current.Session.IsAvailable && (!MyHttpContext.Current.Session.Keys.Any(key => key == "IsNewSession"))) { IRequestCookieCollection requestCookies = MyHttpContext.Current.Request.Cookies; IResponseCookies responseCookies = MyHttpContext.Current.Response.Cookies; // 新しいセッションが開始された MyHttpContext.Current.Session.SetInt32("IsNewSession", 0); // セッションタイムアウト検出用Cookieをチェック if (!requestCookies.Keys.Any(key => key == FxHttpCookieIndex.SESSION_TIMEOUT)) { // セッションタイムアウト検出用Cookie無し → 新規のアクセス // セッションタイムアウト検出用Cookieを新規作成(値は空文字以外、何でも良い) FxCmnFunction.CreateCookieForSessionTimeoutDetection(); MyHttpContext.Current.Session.SetString(FxHttpSessionIndex.DUMMY, "dummy"); } else { // セッションタイムアウト検出用Cookie有り → セッションタイムアウトの可能性 if (string.IsNullOrEmpty(requestCookies.Get(FxHttpCookieIndex.SESSION_TIMEOUT))) { // セッションタイムアウト発生後の新規アクセス // 値が消去されている(空文字に設定されている)場合は、 // 一度エラー or セッションタイムアウトになった後の新規のアクセスである。 // セッションタイムアウト検出用Cookieを再作成(値は空文字以外、何でも良い) FxCmnFunction.CreateCookieForSessionTimeoutDetection(); MyHttpContext.Current.Session.SetString(FxHttpSessionIndex.DUMMY, "dummy"); } else { // セッションタイムアウト発生 // セッションタイムアウト検出用Cookieを消去 // ASP.NETCoreの開発者例外ページには例外処理を差し込めないのでココに実装。 FxCmnFunction.DeleteCookieForSessionTimeoutDetection(); // セッションタイムアウト例外を発生させる throw new FrameworkException( FrameworkExceptionMessage.SESSION_TIMEOUT[0], FrameworkExceptionMessage.SESSION_TIMEOUT[1]); } } } else { // セッション継続中 } } else if (sessionTimeOutCheck.ToUpper() == FxLiteral.OFF) { // セッションタイムアウト検出処理(OFF) } else { // パラメータ・エラー(書式不正) throw new FrameworkException( FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_SWITCH1[0], String.Format(FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_SWITCH1[1], FxLiteral.SESSION_TIMEOUT_CHECK)); } #endregion await base.OnActionExecutionAsync(context, next); #region OnActionExecuted に相当する処理 #endregion }
/// <summary> /// Index Action method to display an error message error information on the screen /// </summary> /// <returns>ActionResult</returns> public ActionResult Index() { //画面にエラーメッセージ・エラー情報を表示する----------------------------- try { // To get an error message from Session string err_msg = (string)Session[FxHttpContextIndex.SYSTEM_EXCEPTION_MESSAGE]; // To get an error information from Session string err_info = (string)Session[FxHttpContextIndex.SYSTEM_EXCEPTION_INFORMATION]; // Remove exception information from Session Session.Remove(FxHttpContextIndex.SYSTEM_EXCEPTION_MESSAGE); Session.Remove(FxHttpContextIndex.SYSTEM_EXCEPTION_INFORMATION); // To encode error message and display on Error screen ViewBag.label1Data = CustomEncode.HtmlEncode(err_msg); // To encode error information and display on Error screen ViewBag.label2Data = CustomEncode.HtmlEncode(err_info); bool sessionAbandonFlag = false; if (Session[FxHttpContextIndex.SESSION_ABANDON_FLAG] != null) { sessionAbandonFlag = (bool)Session[FxHttpContextIndex.SESSION_ABANDON_FLAG]; } Session.Remove(FxHttpContextIndex.SESSION_ABANDON_FLAG); // ------------------------------------------------------------------------ //画面にフォーム情報を表示する--------------------------------------------- NameValueCollection form = (NameValueCollection)Session[FxHttpContextIndex.FORMS_INFORMATION]; Session.Remove(FxHttpContextIndex.FORMS_INFORMATION); if (form != null) { //foreach foreach (string strKey in form) { if (form[strKey] == null) { //Add key and value to PositionData list_form.Add(new PositionData(strKey, "null")); } else { //Add key and value to PositionData list_form.Add(new PositionData(strKey, CustomEncode.HtmlEncode(form[strKey].ToString()))); } } //データバインド ViewBag.list_form = list_form; } // 画面にセッション情報を表示する------------------------------------------ if (Session != null) { //foreach foreach (string strKey in Session) { if (Session[strKey] == null) { //Add key and value to PositionData list_session.Add(new PositionData(strKey, "null")); } else { //Add key and value to PositionData list_session.Add(new PositionData(strKey, CustomEncode.HtmlEncode(Session[strKey].ToString()))); } } //データバインド ViewBag.list_session = list_session; } // セッション情報を削除する------------------------------------------------ if (sessionAbandonFlag) { // セッション タイムアウト検出用Cookieを消去 // ※ Removeが正常に動作しないため、値を空文字に設定 = 消去とする // Set-Cookie HTTPヘッダをレスポンス Response.Cookies.Set(FxCmnFunction.DeleteCookieForSessionTimeoutDetection()); try { // セッションを消去 Session.Abandon(); } catch (Exception ex) { // このカバレージを通過する場合、おそらく起動した画面のパスが間違っている。 string err_str = "このカバレージを通過する場合、おそらく起動した画面のパスが間違っている。"; #if DEBUG Debug.WriteLine(err_str); Debug.WriteLine(ex.Message); #endif ViewBag.label1Data = CustomEncode.HtmlEncode(err_str); ViewBag.label2Data = CustomEncode.HtmlEncode(ex.Message); } } } catch (Exception ex) { // 開発用エラー画面でエラー(無限ループになるのでエラーを潰している)。 string err_str = "開発用エラー画面でエラー(無限ループになるのでエラーを潰している)。"; #if DEBUG Debug.WriteLine(err_str); Debug.WriteLine(ex.Message); #endif ViewBag.label1Data = CustomEncode.HtmlEncode(err_str); ViewBag.label2Data = CustomEncode.HtmlEncode(ex.Message); } return(View()); }