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

B

ben

..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.
 
B

bruce barker

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)
..

| .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.
 
B

ben

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?
 
K

Kevin Spencer

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top