ASP.NET Saving Global Variables - Available from Every Page

I create a large application, and I usually use a simple session to store private global information, however, since the application can be quite large, I believe this may be a problem due to the number of memory sessions that it might have.

Is there a better way to store such variables?

For example, when a user logs in, I want to store data about this user and display it where necessary, without having to query the database each time.

+3
source share
7 answers

- , , . ASP.NET , .

Cache , .

, , - , , , ( ).

, "". , . , Session, , , , .

+3

cookie -

:

1), sql - asp.net SQL-, , ( )

2), sql - , , - - - ( )

- STICKY SESSIONS - - , -

3) .net 2.0, , - XML -/ / : )

. cookie

+3

. , ...

+1

cookie . , , - , cookie , httpcontext .. ; cookie.cs .vb.

SetCookieValue(someValue, cookieName); //there will be some expiration concerns here as well

myValue = GetCookieValue(cookieName);

.

+1

, , - , , .

0

, , ASP.NET . , MSSQL. -, , , .

0

, , ​​ . , , , .

It is also possible that moving from the default session state provider to the SQL provider or server state provider will alleviate the memory problem.

You can use the cache, but the cache is an application. You will need to qualify Cache entries user ID or session identifier: Cache[userID + ".MyCacheEntry"].

In no case do not use static variables to store this data. As suggested in the subject line, they are applied, and not for each user.

0
source

Source: https://habr.com/ru/post/1705803/


All Articles