Asax global file

What is the global asax file for? I want to declare a custom object dictionary that will be used on all pages of the application. Where can I declare this dictionary?

Thank.

+3
source share
4 answers

The Global.asax file is designed to define application-level event handling. There are various events such as launching an application, starting a session ... here is a link to the MSDN documentation: http://msdn.microsoft.com/en-us/library/fwzzh56s.aspx .

For your scenario, use the session start event to save information for the session.

+2
source

Global.asax , . (.. ), . , , - , - . (. MSDN.)

:

public static class SessionObjects
{
    public static Dictionary<DateTime, List<int>> MySessionStoredLists
    {
            get
            {
                    var session = HttpContext.Current.Session;
                    if (session == null) throw new InvalidOperationException();
                    var fromSession = (Dictionary<DateTime, List<int>>)session["MySessionStoredLists"];
                    if (fromSession == null)
                    {
                            fromSession = new Dictionary<DateTime, List<int>>();
                            MySessionStoredLists = fromSession;
                    }
                    return fromSession;
            }
            private set
            {
                session["MySessionStoredLists"] = value;
            }
    }
}

, - - ? ?

+5

Global.asax , : , , ... , , Session.

+3

global.asax , . MSDN.

( ), Session_Start event

+1

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


All Articles