Shared, why not a 'Local Shared' (re: Session and ViewState dislike)

Discussion in 'ASP .Net' started by ben, Nov 12, 2004.

  1. ben

    ben Guest

    ..NET allows the use of Shared module-level vars to share a variable
    between connections to our web-based app. So why doesn't .NET allow
    us to have an implementation of a 'Local Shared' module-level variable
    that has its value maintained per connection.

    At the moment the only ways to achieve this is to use Session or
    ViewState which personally I don't like, a) Session means using an
    additional method getting setting ariable values, doesn't have type
    checking etc, b) ViewState is horrible when you have relativily small
    amounts of data in your variables as the data is stored in the form
    which effects the size of the page.

    If there is an alternative that people are using I would be very
    interested to hear it.
     
    ben, Nov 12, 2004
    #1
    1. Advertising

  2. ben

    bruce barker Guest

    the web is stateless. as a connection only lasts the lifetime of one page
    request (render or postback), local variables handle this.

    -- bruce (sqlwork.com)
    ..

    "ben" <> wrote in message
    news:...
    | .NET allows the use of Shared module-level vars to share a variable
    | between connections to our web-based app. So why doesn't .NET allow
    | us to have an implementation of a 'Local Shared' module-level variable
    | that has its value maintained per connection.
    |
    | At the moment the only ways to achieve this is to use Session or
    | ViewState which personally I don't like, a) Session means using an
    | additional method getting setting ariable values, doesn't have type
    | checking etc, b) ViewState is horrible when you have relativily small
    | amounts of data in your variables as the data is stored in the form
    | which effects the size of the page.
    |
    | If there is an alternative that people are using I would be very
    | interested to hear it.
     
    bruce barker, Nov 12, 2004
    #2
    1. Advertising

  3. ben

    ben Guest

    I agree, I've been developing web-apps for nearly 10 years, but why must
    we use Sessiob, why not in the same way we have "Public Shared" have
    "Public Local" which simply stored the variable in session?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    ben, Nov 12, 2004
    #3
  4. In a Module, everything is Shared (static). That is what a Module IS. Shared
    means that the value is not stored as a copy in an instance on the Stack,
    but exists for the lifetime of the Module, in the heap.

    As bruce pointed out, and if you've been developing web apps for 10 years.
    you should know, HTTP is stateless, and web apps operate in a stateless
    environment. This means that Page instances exist "in a vacuum" so to speak.
    They are created and destroyed in milliseconds with each new Request.
    Therefore, there has to be some means of persisting data that can be used
    across the entire application, across page instances of individual users,
    and across page instances of a single user.

    Due to their nature as existing in a more or less permanent region of memory
    in the application heap, shared (static) data can be accessed by any member
    of the application. Other than that, as HTTP is stateless, it is necessary
    to construct some means of persisting data otherwise. Application memory
    space is global to all entities in the application. For pages that must
    persist data across PostBacks, ViewState was created. In order to keep track
    of data that is unique to a user, but must be available to all page
    instances for that user, Session was created. The Session ID is stored on
    the client, as the client must inform the server of its identity across
    various Requests, each of which occurs "in a vacuum" so to speak. The actual
    data is stored in memory in the application memory space on the server.

    As to why you "must" use Session, the answer is "there is absolutely no
    reason why you must use Session." In fact, the .Net platform provides all
    the tools you need to create your own custom version of ASP.Net if you like,
    and you can create everything from custom HttpHandlers to your own custom
    memory caches if you like. And if you manage to come up with tools that work
    better than the ones Microsoft provides in ASP.Net, let them know, as I'm
    sure they would hire you in a heartbeat. On the other hand, Microsoft spent
    billions of dollars in research coming up with ASP.Net, and have provided
    the best that they can think of. Still, anything is possible, given enough
    monkeys and enough typewriters.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Neither a follower
    nor a lender be.


    "ben" <> wrote in message
    news:#...
    > I agree, I've been developing web-apps for nearly 10 years, but why must
    > we use Sessiob, why not in the same way we have "Public Shared" have
    > "Public Local" which simply stored the variable in session?
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Kevin Spencer, Nov 15, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. V. Jenks
    Replies:
    5
    Views:
    372
  2. Kyler Laird
    Replies:
    0
    Views:
    291
    Kyler Laird
    Jan 18, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,074
    Smokey Grindel
    Dec 2, 2006
  4. Stefan Reich

    I strongly dislike Python 3

    Stefan Reich, Jun 26, 2010, in forum: Python
    Replies:
    1
    Views:
    312
    Lawrence D'Oliveiro
    Jun 27, 2010
  5. Thomas Jollans

    Re: I strongly dislike Python 3

    Thomas Jollans, Jun 26, 2010, in forum: Python
    Replies:
    52
    Views:
    1,520
    Chris Rebert
    Jul 2, 2010
Loading...

Share This Page