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 8095273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:04:16+00:00 2026-06-05T21:04:16+00:00

I have just recently got involved in a classic ASP.NET project which contains lots

  • 0

I have just recently got involved in a classic ASP.NET project which contains lots of storing and reading values from the session and query strings. This could look something like the following:

Session["someKey"]=someValue;

And somewhere else in the code the value in the session is read. Clearly this violates the DRY principle since you’ll have the literal string key spread out all over the code. One way to avoid this could be to store all keys as constants that could be referenced everywhere there is a need to read and write to the session. But I’m not sure that’s the best way to do it. How would you recommend I best handle this so that I don’t violate the DRY principle?

  • 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-05T21:04:18+00:00Added an answer on June 5, 2026 at 9:04 pm

    Create a separate public class where you can define your constants, e.g

    public class SessionVars
    {
       public const string SOME_KEY = "someKey";
       public const string SOME_OTHER_KEY = "someOtherKey";
    }
    

    and then anywhere in your code you can access session variables like this:

    Session[SessionVars.SOME_KEY]=someValue;
    

    This way you can get IntelliSence and other bells and whistles.

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

Sidebar

Related Questions

I have just recently run into an issue running an asp.net web app under
I have a project using DevExpress 8.3 (2008.3) which I just recently upgraded to
We have just recently got our SVN server installed. My developers have added the
I've been programming for many years and have just recently got the RoR itch.
I have recently just created Java project using Eclipse that requires 2 JAR files
So just recently, my async server code which relies on pthread_mutex_timedlock seem to have
I have a simple object called Entry , which until just recently only had
i just recently asked a question and got help but i have another problem
I have MVC architecture for my project and recently I got a weird problem.
I have just recently got interested in the Google Analytics plugin but found out

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.