Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:03:15+00:00 2026-06-12T12:03:15+00:00

as I was trying to test/debug my applications by using QueryString as data to

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:03:16+00:00Added an answer on June 12, 2026 at 12:03 pm

    You can’t just do the same with sessions :

    First, Http.Current.Session is not a NameValueCollection (like QueryString), but an HttpSessionState (which explains your Object does not match target type message)

    Then, HttpSessionState has an IsReadonly property, but… it’s readonly (you can’t set it). When the IsReadonly property from NameValueCollection is settable.

    So… No way (at least this way).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to test my application using Selenium tool via the Hudson plugin
I've got a test I'm trying to debug and I've noticed that the values
I'm trying to debug my code which is being executed from a unit test
Trying to test the option of replacing our internal data access layer with Entity
Im trying to test my successfully creates a new user after login (using authlogic).
I am trying to test some async methods involving the HttpClient work with vs
I'm trying to test using SFML's full screen mode, however it crashes every time
I'm trying to debug and test my application with a Dell Windows Mobile device
I am trying to host my service using following configuration. <system.serviceModel> <services> <service name=Test.MyService
I am trying to test an app on my iOS 4.2.1 device using XCode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.