public static void HtmlDecodeTest(string str) { try { // Performs encryption using the components touryo. string strValue = CustomEncode.HtmlEncode(str); // Performs decrypted using the components touryo. string str1 = CustomEncode.HtmlDecode(strValue); // Check whether it is decrypted into the original string. Assert.AreEqual(str, str1); } catch (Exception ex) { // Print a stack trace when an exception occurs. Console.WriteLine(ex.StackTrace); throw; } }
/// <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> /// 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()); }