ASP.NET Entry Point?

后端 未结 5 822
长情又很酷
长情又很酷 2021-02-05 05:14

Just created a blank \"ASP.NET Web Application\". Where\'s the entry point?

I see \"Default.aspx\" which seems to be the default template that calls. \"Site.Master\" whi

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 05:55

    I think I wanted to know the first line of code that gets hit when a new request comes in.

    The HttpApplication class contains the first line of code of your application. Its constructor is very much the entry point for your application. From the docs:

    After all core application objects have been initialized, the application is started by creating an instance of the HttpApplication class.

    There are two canonical ways to write the first line of code that gets hit for a new request. Both involve creating a Global.asax file and handling its events.

    To handle application events or methods, you can create a file named Global.asax in the root directory of your application.

    You will want to handle Application_Start and/or Application_BeginRequest.

    • Application_Start is for code that gets hit on the very first request to the application. Each time we restart the application, the next request will enter here. This is per application startup.
    • Application_BeginRequest is for code that gets hit on each request to the application. This is per request.

    Of course, this all changes with ASP.NET Core.

提交回复
热议问题