简体   繁体   中英

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 ?

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.

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.

The global.asax.cs is what's known as a codebehind file of global.asax. There is no real functional difference between the two of those files.The codebehind is simply designed to separate concerns between markup and server-side code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM