as I was trying to test/debug my applications
by using QueryString
as data to evaluate .
I was trying to implement same methods via session variables
in my other post regarding QueryStrings I was searching for a way to manipulate the QueryString via helper method ..
now I was trying to move on and triyng same thing to Session Variables using same method as with QueryStrings
code is
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);
}
}
}
the error i get on line that tries to set value of read only to false : as i am still not yet experienced enough with .net i couldn't understand where did i go wrong or ...is it totally impossible to implement that on session variables.
Object does not match target type.
trying it on QueryString and working with this method is fine as in this line of code:
isReadOnly.SetValue(HttpContext.Current.Request.QueryString, false, null);