Store Web Application Properties in Memory

Discussion in 'ASP General' started by vunet, Dec 1, 2009.

  1. vunet

    vunet Guest

    Hello,
    I would like to know what are the best practices one could share to
    store global properties for a web application. For example, upon
    access of this application (i.e. website in classic ASP), I would
    store the menu text retrieved from database, application domain to
    construct full file paths, admin email, database settings, template
    settings, etc.
    I tried Application object which kinda works for me but if there are 2
    instances of application on one server, things get messed up a bit.
    Please suggest your solution.
    Thank you.
     
    vunet, Dec 1, 2009
    #1
    1. Advertisements

  2. vunet

    Bob Barrows Guest

    Two instances? Of the same application? That seems to be contrary to the
    definition of Application.
    Could you explain how things "things get messed up a bit"?

    Anyways, you have three alternatives:
    1. store the values in a database (including a text or xml file)
    2. store them in Application
    3. store them in Session

    There are no "best practices". The technique you choose depends on the
    needs of the application.
     
    Bob Barrows, Dec 1, 2009
    #2
    1. Advertisements

  3. vunet

    vunet Guest

    Yes, for example you can have multiple instances of a WordPress web
    application in simply different folders, can't you?
    Application object in ASP is shared between all web applications.
    Let's say I have an account with hosting company. I can create more
    than one websites under 2 different folders. If one website is adding
    Application("somedata") value, then another one can get Application
    ("somedata") value when in fact I want this to be different.
    I already do... but see above.
     
    vunet, Dec 1, 2009
    #3
  4. vunet

    Bob Barrows Guest

    As long as they are not subfolders of a single virtual directory, they
    will be considered separate applications, each with its own Application
    object:

    From http://msdn.microsoft.com/en-us/library/ms525360.aspx
    "An ASP-based application is defined as all the .asp files in a virtual
    directory and its subdirectories"

    Only if the hierarchy looks like this in IIS Manager will they be
    considered a single application:

    Default Web Site
    |
    --Wordpress
    |
    ---Wordpress1
    |
    ---Wordpress2

    Wordpress1 and Wordpress2 are simply part of the Wordpress application.
    If you are thinking each is considered a separate application, then that
    is the basis of your problem.
    Err ... no it isn't. See the above definition. Each application has its
    own application object.
    Have you tried this? I have, and I can categorically say that each
    application has its own values in its own application object. On our
    companies intranet, I have a website whose host header value is nnwadev.
    It contains two folders (plus several others, but they aren't relevant):
    acctflashrpt and test. a page called
    http://nnwadev/acctflashrpt/applicationtest.asp contains this code:
    <%
    application("test") = "acctflashrpt test"
    response.write "Application(""test"") contains '" & application("test")
    & "'"
    %>

    In the separate test folder I have another page called
    http://nnwadev/test/apptest.asp that contains this code:
    <%
    response.write "Application(""test"") contains '" & application("test")
    & "'"
    %>

    When I run the first page, I see:
    Application("test") contains 'acctflashrpt test'
    When I then navigate to //nnwadev/test/apptest.asp, I see
    Application("test") contains ''

    Two folders = two separate applications.
     
    Bob Barrows, Dec 1, 2009
    #4
  5. vunet

    vunet Guest

    It looks like I want to make Wordpress1 and Wordpress2 to be separate
    applications even though it is one "application". Thus I cannot use
    Application object for my purposes. And I do not want to use database
    because this application is supposed to have no database dependency.
    So I am left with session object according to your answer. So then am
    I supposed to create a bunch of session objects for each property? The
    object may have a long string of text (menu html/xml text). This does
    not seem to be a very good solution... does it?
    Thanks
     
    vunet, Dec 1, 2009
    #5
  6. vunet

    Bob Barrows Guest

    Yeah, they can only be separate applications if they are arranged like
    this:

    Default Web Site
    |
    ---Wordpress1
    |
    ---Wordpress2

    No. Session is not a good solution for data that is intended to span
    sessions. My inclination would be to store it in a file on the server,
    especially the xml. The menu html sounds like it needs to be a
    server-side include file anyways.
     
    Bob Barrows, Dec 1, 2009
    #6
  7. vunet

    Dan Guest

    If your hosting solution allows you to mark the Wordpress1 and Wordpress2 as
    ASP Application Roots then you can use the Application object in each and
    they will be independent. Applications are not required to be virtual
    directories directory under the root directory, and also any virtual
    directory under the root isn't automatically going to be a separate
    Application. The IIS management interface lets you set Application roots on
    any folder anywhere in the tree.
     
    Dan, Dec 2, 2009
    #7
  8. vunet

    Bob Barrows Guest

    Hmm ... let me confirm this. I had never tried doing that ...
    Yes, you are absolutely correct. I have now set this situation up on my
    web server and each application, as defined in IIS Manager, has its own
    application object. Thanks for teaching me something new.

    I still submit that some of what vunet is looking to do is more
    appropriate for server-side include (ssi) files.
     
    Bob Barrows, Dec 2, 2009
    #8
  9. vunet

    Dan Guest

    I'm glad I was able to teach you something, but I've got a long way to go
    before I get close to what you've taught me :p
    An SSI would work fine, so long as the variable names (actually Constants
    might be better here) are very clearly defined to reduce the risk of them
    being changed elsewhere in the application code. With server side caching
    the performance difference should be minimal in terms of actual page
    execution time, but there may be a memory overhead associated with this; I
    can't remember if includes are cached independently of their parents, or
    only the final compiled pages are compiled - in the former case an SSI might
    actually usually less memory as there is not collection object overhead,
    whereas in the latter case having those same variables/constants cached in
    memory could use up more if the number of different pages in the application
    is large enough.
     
    Dan, Dec 2, 2009
    #9
  10. vunet

    vunet Guest

    I think what I am really looking for in an ideal world is a singleton
    alternative in classic ASP.
     
    vunet, Dec 2, 2009
    #10
  11. vunet

    vunet Guest

    Will that work:

    class MySingleton
    public function getInstance(ApplicationID)
    if not isObject(application(ApplicationID)) then
    set application(ApplicationID) = new MySingleton
    end if
    set getInstance = application("MySingleton")
    end sub
    end class

    'usage
    set instance = (new MySingleton).getInstance(ApplicationID)

    Note: ApplicationID may be something unique (for example I could use
    website's path with removed slashes) and if 2 websites share one
    Application object the code above will handle this by passing
    appropriate parameter (ApplicationID).
     
    vunet, Dec 2, 2009
    #11
  12. vunet

    Bob Barrows Guest

    You're reinventing the wheel. You can prevent two websites from sharing
    the same aplication object by simply creating an application for each
    folder in IIS Manager. See the previous discussion where Dan convinced
    me my initial assertion was incorrect.

    Your class will have problems if two threads attempt to create
    MySingleton simultaneously.
     
    Bob Barrows, Dec 2, 2009
    #12
  13. vunet

    vunet Guest

    Thank you. My website package will be distributed to environments
    which I have no control of - that's why I wanted a simpler solution.
    Though it is good to know I could do what I learned from posts above.
    Should I do Application.Lock/Unlock to synch the access?
     
    vunet, Dec 2, 2009
    #13
  14. vunet

    Bob Barrows Guest

    I would be more inclined to provide a setup program to set this up
    correctly than attempt to roll my own. It will require an administrator
    on the web server to run the script or setup program ...
    But then again, I'm strictly an intranet developer ... maybe this is
    something internet developers need to do.
    Yes, that is the standard practice.
     
    Bob Barrows, Dec 2, 2009
    #14
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.