Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between global.asax and global.asax.cs

Tell me about the difference between global.asax and global.asax.cs ?

and

If i click the both file in my solution explorer , it's goes to only server (asax.cs) side ,Why and how ? and can i see client side(global.asax) page ?

like image 842
Ramesh Rajendran Avatar asked Oct 21 '13 07:10

Ramesh Rajendran


People also ask

What is global asax CS?

Global. asax is the asp.net application file. It is an optional file that handles events raised by ASP.NET or by HttpModules. Mostly used for application and session start/end events and for global error handling.

What is difference between web config and global asax?

Global. asax contains code which is executed. Web. config contains configuration settings of web application, for example connection string, included libraries, namespaces, users and groups access permissions to virtual directories, etc.

What is global asax in MVC?

The Global. asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event. The file in Listing 1 contains the default Global. asax file for an ASP.NET MVC application.

What is global asax in .NET core?

Global. ASP.NET Core introduced a new mechanism for bootstrapping an app. 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.


2 Answers

Global.asax is the markup file that goes with the "code-behind" file .asax.cs. But the markup file isn't used for much, as far as I know (all the content normally goes into the code-behind file). You can view it, though, by right-clicking on it in Solution Explorer, and then "view markup".

You can't add content to the markup, only a few attributes:

<%@ Application Codebehind="Global.asax.cs" 
                Inherits="WebApplication1.Global" 
                Language="C#" %>

The MSDN docs seem to confirm that the only purpose of global.asax is to add/override handlers for application-level events:

The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules.

like image 77
McGarnagle Avatar answered Oct 13 '22 00:10

McGarnagle


You can hit F7 when in codebehind file to display .asax markup.

The global.asax behaves somewhat like an aspx file, being compiled when the application starts.

You can even put your methods (like Application_Start) in a script runat="server" element in the global.asax.

I doubt it is good practice, but this should allow to hot-edit a running application (which should trigger a recycle I guess) It will then be compiled dynamically.

like image 24
jbl Avatar answered Oct 13 '22 01:10

jbl