/// <summary>開始方法を規定する(スレッドプール)</summary> /// <returns> /// true:開始した /// false:開始できなかった /// </returns> public bool StartByThreadPool() { lock (MyBaseAsyncFunc._lock) { // スレッド数の最大数(既定値は、1) int maxThreadCount = FxCmnFunction.GetNumFromConfig(FxLiteral.MAX_THREAD_COUNT, 1); if (BaseAsyncFunc.ThreadCount >= maxThreadCount) { // 開始できなかった return(false); } // スレッド数インクリメント&画面ロック BaseAsyncFunc.ThreadCount++; this.WindowLock(); // 非同期実行(スレッドプール) ThreadPool.QueueUserWorkItem(new WaitCallback(this.CmnCallbackP), this); // 開始した return(true); } }
/// <summary>Master PageにEvent Handlerを実装可能にしたのでそのテスト。</summary> /// <param name="fxEventArgs">Event Handlerの共通引数</param> /// <returns>URL</returns> protected string UOC_btnMPButton_Click(FxEventArgs fxEventArgs) { //Response.Write("UOC_btnMPButton_Clickを実行できた。"); ((Label)FxCmnFunction.FindWebControl(this.Page.Controls, "lblResult")).Text = "UOC_btnMPButton_Clickを実行できた。"; return(""); }
/// <summary>開始方法を規定する</summary> /// <returns> /// true:開始した /// false:開始できなかった /// </returns> public bool Start() { lock (MyBaseAsyncFunc._lock) { // スレッド数の最大数(既定値は、1) int maxThreadCount = FxCmnFunction.GetNumFromConfig(FxLiteral.MAX_THREAD_COUNT, 1); if (BaseAsyncFunc.ThreadCount >= maxThreadCount) { // 開始できなかった return(false); } // スレッド数インクリメント&画面ロック BaseAsyncFunc.ThreadCount++; this.WindowLock(); // 非同期実行(スレッド) Thread th = new Thread(this.CmnCallback); th.Start(); // 開始した return(true); } }
/// <summary>セッションを消去</summary> /// <remarks>併せてSessionタイムアウト検出用Cookieを消去</remarks> protected void FxSessionAbandon() { // セッションタイムアウト検出用Cookieを消去 FxCmnFunction.DeleteCookieForSessionTimeoutDetection(); // セッションを消去 MyHttpContext.Current.Session.Clear(); }
/// <summary>User ControlにEvent Handlerを実装可能にしたのでそのテスト。</summary> /// <param name="fxEventArgs">Event Handlerの共通引数</param> /// <returns>URL</returns> protected string UOC_sampleChildControl_btnUCChildButton_Click(FxEventArgs fxEventArgs) { ((Label)FxCmnFunction.FindWebControl(this.Page.Controls, "lblResult")).Text = "sampleChildControl.ascxのbtnUCChildButtonのClickイベントを、sampleScreen_cc.UOC_sampleChildControl_btnUCChildButton_Clickで実行"; return(""); }
/// <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 })); }
// 2009/07/21-start #region コントロール取得&イベントハンドラ設定 /// <summary>コントロール取得&イベントハンドラ設定(下位互換)</summary> /// <param name="ctrl">コントロール</param> /// <param name="prefix">プレフィックス</param> /// <param name="eventHandler">イベント ハンドラ</param> /// <param name="controlHt">ディクショナリ</param> internal static void GetCtrlAndSetClickEventHandler( Control ctrl, string prefix, object eventHandler, Dictionary <string, Control> controlHt) { #region チェック処理 // コントロール指定が無い場合 if (ctrl == null) { // 何もしないで戻る。 return; } // プレフィックス指定が無い場合 if (prefix == null || prefix == "") { // 何もしないで戻る。 return; } #endregion #region コントロール取得&イベントハンドラ設定 // コントロールのIDチェック if (ctrl.ID == null) { // コントロールID無し } else { // コントロールID有り // コントロールのID長確認 if (prefix.Length <= ctrl.ID.Length) { // 指定のプレフィックス if (prefix == ctrl.ID.Substring(0, prefix.Length)) { // イベントハンドラを設定する。 if (prefix == GetConfigParameter.GetConfigValue(MyLiteral.PREFIX_OF_CHECK_BOX)) { // CHECK BOX CheckBox checkBox = FxCmnFunction.CastByAsOperator <CheckBox>(ctrl, prefix); // ハンドラをキャストして設定 checkBox.CheckedChanged += (EventHandler)eventHandler; // ディクショナリに格納 // ControlHt.Add(ctrl.ID, ctrl); // ControlHt[ctrl.ID] = ctrl; FxCmnFunction.AddControlToDic(ctrl, controlHt); // 2011/02/12 } } } } #endregion #region 再帰 // 子コントロールがある場合、 if (ctrl.HasControls()) { // 子コントロール毎に foreach (Control childCtrl in ctrl.Controls) { // 再帰する。 MyCmnFunction.GetCtrlAndSetClickEventHandler(childCtrl, prefix, eventHandler, controlHt); } } #endregion }
// 2009/07/21-start #region コントロール取得&イベントハンドラ設定 /// <summary>コントロール取得&イベントハンドラ設定(下位互換)</summary> /// <param name="ctrl">コントロール</param> /// <param name="prefix">プレフィックス</param> /// <param name="eventHandler">イベント ハンドラ</param> /// <param name="controlHt">ディクショナリ</param> internal static void GetCtrlAndSetClickEventHandler( Control ctrl, string prefix, object eventHandler, Dictionary <string, Control> controlHt) { #region チェック処理 // コントロール指定が無い場合 if (ctrl == null) { // 何もしないで戻る。 return; } // プレフィックス指定が無い場合 if (prefix == null || prefix == "") { // 何もしないで戻る。 return; } #endregion #region コントロール取得&イベントハンドラ設定 // コントロールのIDチェック if (ctrl.ID == null) { // コントロールID無し } else { // コントロールID有り // コントロールのID長確認 if (prefix.Length <= ctrl.ID.Length) { // 指定のプレフィックス if (prefix == ctrl.ID.Substring(0, prefix.Length)) { // イベントハンドラを設定する。 if (prefix == GetConfigParameter.GetConfigValue(MyLiteral.PREFIX_OF_CHECK_BOX)) { // CHECK BOX CheckBox checkBox = null; try { // キャストできる checkBox = (CheckBox)ctrl; } catch (Exception ex) { // キャストできない throw new FrameworkException( FrameworkExceptionMessage.CONTROL_TYPE_ERROR[0], String.Format(FrameworkExceptionMessage.CONTROL_TYPE_ERROR[1], prefix, ctrl.GetType().ToString()), ex); } checkBox.CheckedChanged += (EventHandler)eventHandler; // ディクショナリに格納 // ControlHt.Add(ctrl.ID, ctrl); // ControlHt[ctrl.ID] = ctrl; FxCmnFunction.AddControlToDic(ctrl, controlHt); // 2011/02/12 } } } } #endregion #region 再帰 // 子コントロールがある場合、 if (ctrl.HasControls()) { // 子コントロール毎に foreach (Control childCtrl in ctrl.Controls) { // 再帰する。 MyCmnFunction.GetCtrlAndSetClickEventHandler(childCtrl, prefix, eventHandler, controlHt); } } #endregion }
/// <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()); }
/// <summary> /// アクション メソッドの呼び出し前に呼び出されます。 /// Controller.OnActionExecuting メソッド (System.Web.Mvc) /// http://msdn.microsoft.com/ja-jp/library/system.web.mvc.controller.onactionexecuting.aspx /// </summary> /// <param name="filterContext"> /// 型: System.Web.Mvc.ActionExecutingContext /// 現在の要求およびアクションに関する情報。 /// </param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { // Calling base class method. base.OnActionExecuting(filterContext); #region セッションタイムアウト検出処理 // セッションタイムアウト検出処理の定義を取得 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 (Session.IsNewSession) { // 新しいセッションが開始された // セッションタイムアウト検出用Cookieをチェック HttpCookie cookie = Request.Cookies.Get(FxHttpCookieIndex.SESSION_TIMEOUT); if (cookie == null) { // セッションタイムアウト検出用Cookie無し → 新規のアクセス // セッションタイムアウト検出用Cookieを新規作成(値は空文字以外、何でも良い) Response.Cookies.Set(FxCmnFunction.CreateCookieForSessionTimeoutDetection()); Session[FxHttpSessionIndex.DUMMY] = "dummy"; } else { // セッションタイムアウト検出用Cookie有り → セッションタイムアウトの可能性 if (cookie.Value == "") { // セッションタイムアウト発生後の新規アクセス // 値が消去されている(空文字に設定されている)場合は、 // 一度エラー or セッションタイムアウトになった後の新規のアクセスである。 // セッションタイムアウト検出用Cookieを再作成(値は空文字以外、何でも良い) Response.Cookies.Set(FxCmnFunction.CreateCookieForSessionTimeoutDetection()); Session[FxHttpSessionIndex.DUMMY] = "dummy"; } else { // セッションタイムアウト発生 // エラー画面で以下の処理を実行する。 // ・セッションタイムアウト検出用Cookieを消去 // ・セッションを消去 // セッションタイムアウト例外を発生させる 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 }