What is the use of ASAX extensions?

3

Finally, I started working with C #. I'm working on a SITE-type project and I'm using Visual Studio.

I came across a file where you should apparently put the global settings there, which is Global.asax .

It seems to have a different syntax than other files, such as cs and aspx .

Example:

<%@ Application Language="C#" %>

<script runat="server">    
    void Application_BeginRequest(object sender, EventArgs e)
    {
          if (Request.Url.AbsolutePath.EndsWith("/")) {
                 Server.Transfer("~/index.aspx");
          }
    }

</script>
  • What is the purpose of this extension asax ?

  • Why does it have a different syntax?

  • Only the Global.asax file has this extension generally, or can others also have this extension?

asked by anonymous 28.06.2017 / 14:23

4 answers

3
  

What is the purpose of this asax extension?

I believe it is only used for the file Global.asax and this file as stated in this SOen response aims to write a code that "responds" to the "application core" through certain events, such as when your application starts, ends or when a session starts and ends, it is possible to detect unhandled errors in the application.

  

Why does it have a different syntax?

I think it's because it's not an ASP.NET page, but an event handler, which occurs at the core of the application.

  

Only the Global.asax file has this extension generally, or can others also have this extension?

I believe that other files with this extension are "rejected" if you try to execute them in your application (or perhaps in the request), each extension has a meaning:

  • S er P age and I believe that "X" is "extended"
  • A S erver A pplication and "X" may be "extended" / li>

Global.asax Events

And as per this response of SOen each event has a specific functionality

  • .aspx : This is triggered when an ASP.NET application is initialized for the first time.

  • .asax : It is fired when an application is destroyed.

  • Application_Init : Is triggered when an unhandled exception occurs.

  • Application_Disposed : Is triggered when the first instance of Application_Error is created. This allows you to create objects that are accessible in all Application_Start instances.

  • HttpApplication : It is fired when the last instance of HttpApplication is destroyed. This only fires during the application's "life cycle".

  • Application_End : Fires when an application receives an HTTP request.

  • HttpApplication : Last event to be triggered for a request.

  • Application_BeginRequest : It is triggered before a page using the ASP.NET framework starts running the event handler for a page or a web service.

  • Application_EndRequest : Is triggered when asp.net completes an authorization request. It allows cache modules to meet the cache request, ignoring the execution of the handler.

  • Application_PreRequestHandlerExecute : Is triggered when ASP.NET completes the execution handler to allow caching modules to store responses to be used to handle subsequent requests.

  • Application_PostRequestHandlerExecute : This is triggered when the security module established the current user's identity as valid. At this point, the user credentials have been validated.

  • Applcation_PreSendRequestHeaders : Is triggered when the security module has verified that a user can access resources.

  • Application_PreSendContent : It is fired when a new session is created and accessed for the first time. This event is usually used when we want to initialize some session logic.

  • Application_AcquireRequestState : Is triggered when a user session is terminated or expires.

  

If you have any wrong information please notify me, I did not know more than half of these events myself

    
28.06.2017 / 21:20
1

The Global.asax file is a file that Contains application-level events (hence the extension, ASp.net Application ). Its syntax is not particularly different from an ASPX file, except that it is derived from class HttpApplication instead of Page , then the methods and events will vary because of this. But in the end it's all ASP.NET and C # ...

The reason for not using Global.aspx to be chopped with Global.asa of "classic" ASP times, is to assign a rule to the server that prevents the file from being downloaded via HTTP, whereas% are processed and their result is sent as HTML. Likewise, there is the .aspx extension for SOAP services (based on WebService ) and .asmx for generic" handlers "(based on IHttpHandler ).

Finally, the .ashx extension is unique to .asax , because it does not make sense to have more than one application descriptor (which one would the server use?).

    
28.06.2017 / 14:57
0
Hello, for the short experience I have with C #, Global.ASAX serves as a start of your system, it is a manager, it will manage what happens in case of errors and what it does when you start a debug

    
28.06.2017 / 14:31
0

Good morning!

In the ASP.NET architecture, Global.asax is responsible for configuring application and session events.

    
28.06.2017 / 14:52