Why global.asax removed in ASP.NET Core.

bhavna 106 Reputation points
2022-02-15T09:16:54.317+00:00

If global.asax or its parent HttpApplication was part of ASP.NET and not windows native drivers then why can't ASP.NET Core hosting module directly communicate to it without having startup.cs and Main to create the Http request processing pipeline?
I mean why is owin like structure followed over global.asax?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,510 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,146 Reputation points Microsoft Vendor
    2022-02-16T02:51:58.27+00:00

    Hi @bhavna ,

    You can check the official document: Global.asax file replacement

    The entry point for ASP.NET applications is the Global.asax file. Tasks such as route configuration and filter and area registrations are handled in the Global.asax file. This approach couples the application and the server to which it's deployed in a way that interferes with the implementation. In an effort to decouple, OWIN was introduced to provide a cleaner way to use multiple frameworks together. OWIN provides a pipeline to add only the modules needed. The hosting environment takes a Startup function to configure services and the app's request pipeline. Startup registers a set of middleware with the application. For each request, the application calls each of the middleware components with the head pointer of a linked list to an existing set of handlers. Each middleware component can add one or more handlers to the request handling pipeline. This is accomplished by returning a reference to the handler that's the new head of the list. Each handler is responsible for remembering and invoking the next handler in the list. With ASP.NET Core, the entry point to an application is Startup, and you no longer have a dependency on Global.asax. ASP.NET Core uses a similar approach, but doesn't rely on OWIN to handle the entry. Instead, that's done through the Program.cs Main method (similar to console applications) and Startup is loaded through there.

    So, in asp.net core application, the host and application have been decoupled, which provides the flexibility of moving to a different platform in the future.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    3 people found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 64,006 Reputation points
    2022-02-15T17:24:42.423+00:00

    global.asax main use was to hookup events to the asp.net pipeline which was designed for webforms. the HttpApplication was the state passed thru the pipeline. webforms and this pipeline were not ported to core. without the pipeline HttpApplication has no use and also was not ported. the concept of HttpContext was ported.

    the old pipeline was replaced because the event order was confusing, not well defined and slow. asp.net core was about performance and they decided to use a faster async event based, non-blocking i/o pipeline with middleware similar to node.js (whose performance they were trying to beat). the first release of core actually used the node pipeline code. for compatibility the middleware calls are similar to owin (which was a middleware pipeline for old aspx).

    2 people found this answer helpful.
    0 comments No comments

  3. AgaveJoe 28,036 Reputation points
    2022-02-15T12:01:41.077+00:00

    If global.asax or its parent HttpApplication was part of ASP.NET and not windows native drivers then why can't ASP.NET Core hosting module directly communicate to it without having startup.cs and Main to create the Http request processing pipeline?

    I have no idea what you are asking. What problem are you trying to solve in ASP.NET Core?

    I mean why is owin like structure followed over global.asax?

    ASP.NET Core is cross platform and the startup allow you to add only the services the application needs. ASP.NET needs the entire framework iinstalled on the server.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.