C # + WebForms + static - what are the best practices?

I'm definitely not a fan of WebForms, I prefer the .NET world to ASP.NET MVC.

Regardless, I am working on a small part of a very large legacy WebForms application.

I integrate Korzh.com EasyQuery.NET. so that end users can create their own SQL queries based on predefined models made with user-friendly aliases.

This is relevant because the Korzh demo uses Global.asax for its model and
request class along with the session.

Because the legacy WebForms application is very large, Global.asax is not used for specific pages.

My solution was to use private static instead. static works well on the desktop,
but at least it can lead to some upset in WebForms applications.

I found that IsPostBack is not very reliable, and it seems to me that using WebSorm might be the best practice in WebForms. The problem with the Session is that it seems to be transmitted to the client with HTML and can grow very large in kilobytes.

QUESTIONS:

Since static variables reside on the IIS server when used with WebForms, does each user of the WebForms application have the same address space for static variables? (I think the answer is yes).

What are the best practices / guidelines for using / not using static variables with ASP.NET WebForms applications?

.
,
()

P.S.:
Google SO.

+3
1

ASP.NET , -, , , :

public class Global : HttpApplication {
    public static string MyString
}

- , . , . :

  • HttpRuntime.Cache HttpContext.Cache , ( , ).

  • HttpContext.Items - . , , .

  • HttpSessionState, . 4 :

    3.a. InProc, . , , .

    3.b. SqlServer, Sql Server. , . .

    3.c. StateServer, .

    3.d. , ....

  • ViewState, .

HttpRuntime - . , , .. , , , . , , , . .

, .

+10

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


All Articles