評価用のデータとして使用してアプリケーションをテスト/デバッグしようとしてQueryString
いたため。
セッション変数を介して同じメソッドを実装しようとしていました
QueryStringsに関する他の投稿では、ヘルパーメソッドを介してQueryStringを操作する方法を探していました。
今、私はクエリ文字列と同じメソッドを使用して、セッション変数に移動して同じことを試行しようとしていました
コードは
public static class Sesion
{
public sealed class Act
{
public const string edit = "edit", add = "add", remove = "remove", replace = "replace";
}
public static void Modify(string action, string New_Value, string CurSes_ParamName, string NewSession_paramName = null, bool redirectWithNewQuerySettings = false)
{
#region <<=========== reflect to readonly & set QueriString ReadOnly - false ============>>
//HttpContext.Current.Request.QueryString["qs_key"];
// reflect to readonly property
PropertyInfo isReadOnly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isReadOnly.SetValue(HttpContext.Current.Session, false, null);
#endregion
switch (action)
{
case Act.remove:
if (itsNotAnEmptySession())
HttpContext.Current.Session.Remove(CurSes_ParamName);
break;
case Act.replace:
HttHttpContext.Current.Session.Remove(CurSes_ParamName);
HttpContext.Current.Session.Add(NewSession_paramName , New_Value);
break;
case Act.edit:
HttpContext.Current.Session.Set(CurSes_ParamName, New_Value);
break;
case Act.add:
HttpContext.Current.Session.Add(NewSession_paramName , New_Value);
break;
}
isReadOnly.SetValue(HttpContext.Current.Session, true, null);
}
}
}
読み取り専用の値をfalseに設定しようとするオンラインでのエラー:.netの経験がまだ十分でないため、どこで問題が発生したのか理解できませんでした。セッション変数。
Object does not match target type.
QueryStringで試して、このメソッドを操作することは、次のコード行のように問題ありません。
isReadOnly.SetValue(HttpContext.Current.Request.QueryString, false, null);