none
Declaring and storing variables within their scope using C# ASP.NET RRS feed

  • Question

  • I would like some assistance with the following:

    • Declare and store the following variables within their most appropriate scope:
      • Database connection string
      • Frequently used Horse Objects
      • ID of current horse being edited on the page
      • Logged in member id
      • Number of items on member basket
      • Site Name

    Please use sample data where needed

    Thank you in advance


    • Edited by DaveGreen111 Wednesday, December 10, 2014 2:19 PM
    • Moved by Kristin Xie Thursday, December 11, 2014 9:12 AM
    Wednesday, December 10, 2014 2:19 PM

All replies

  • Database connection string

    Web.config

    • Frequently used Horse Objects

    You could cache them in application cache but it's more usual with small systems to just read the data every time out a database.

    • ID of current horse being edited on the page

    Keep a current horse object in user  session

    • Logged in member id

    Keep a user object in user session

    • Number of items on member basket

    Either store the basket in in session or persist it to a database with the user Id as a key.  The latter is less efficient but if you want them to be able to log out, come back the next day and see things in their basket like Amazon do then you need to persist the basket.

    • Site Name

    You can obtain this in code:

    System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
    Or if you want something different then there are some variations on that.
    Or you could store something in application.cache.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.


    • Edited by Andy ONeill Wednesday, December 10, 2014 2:31 PM
    Wednesday, December 10, 2014 2:31 PM
  • Please post questions related to ASP.NET in the ASP.NET forums (http://forums.asp.net ).
    Wednesday, December 10, 2014 5:17 PM