What are ASAX extensions for?

Asked

Viewed 1,252 times

3

Finally, I started working with C#. I am working on a SITE project and I am using Visual Studio.

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

It seems to have a different syntax than other files, such as cs and the 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 file Global.asax has this extension generally, or others may also have this extension?

4 answers

3

What is the purpose of this asax extension?

I believe it’s only used for the archive Global.asax and this file as stated in this reply from Soen is intended to write a code that "responds" to the "core of the application" through certain events, such as when your application starts, ends, or when a session starts and ends, otherwise it is possible to detect manipulated errors in the application.

Why does it have a different syntax?

I believe it is because it is not an Asp.net page but an event handler, which occurs at the core of the application.

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

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

  • .aspx - Toctive Sobserve Pacts and I believe the "X" is from "Extended"
  • .asax - Toctive Sobserve Topplication and the "X" might be from "Extended"

Events of Global.asax

And according to this reply Soen each event has a specific functionality

  • Application_Init: It is triggered when an ASP.NET application is first initialized.

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

  • Application_Error: It is triggered when an untreated Exception occurs.

  • Application_Start: It is triggered when the first instance of HttpApplication is created. This allows creating objects that are accessible in all instances HttpApplication.

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

  • Application_BeginRequest: It is triggered when an application receives an HTTP request.

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

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

  • Application_PostRequestHandlerExecute: It is triggered when a page with Asp.net framework finishes executing a handler event (Handler)

  • Applcation_PreSendRequestHeaders: It is fired before a page that uses Asp.net sends the HTTP headers to whom it has requested (usually the browser).

  • Application_PreSendContent: It is fired before Asp.net sends the content (body/body) to whom you requested it (browser/client).

  • Application_AcquireRequestState: It is triggered when Asp.net picks up the current state (Session state) of the current request.

  • Application_ReleaseRequestState: It is triggered when Asp.net completes the execution of all events.

  • Application_ResolveRequestCache: It is triggered when Asp.net completes an authorization request. It allows cache modules to meet the cache request, ignoring the handler execution.

  • Application_UpdateRequestCache: It is triggered when ASP.NET completes the manipulator run to allow cache modules to store responses to be used to handle subsequent requests.

  • Application_AuthenticateRequest: It is triggered when the security module has established the current user’s identity as valid. At this point, the user’s credentials have been validated.

  • Application_AuthorizeRequest: It fires when the security module has verified that a user can access resources.

  • Session_Start: It is triggered 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.

  • Session_End: It is triggered when a user session is finished or is expired.

If you have any wrong information please notify me, I myself was unaware more than half of these events

1

The archive Global.asax is a file that contains the application level events (hence the extension, Asp.net Application). Its syntax is not particularly different from an ASPX file, except that it derives from the class Httpapplication instead of Page, then the methods and events will vary because of this. But ultimately it’s all ASP.NET and C#...

The reason not to use Global.aspx, outside chorus with the Global.asa of the "classic" ASP times, is to assign a rule to the server that prevents the file from being downloaded via HTTP, while the pages .aspx are processed and its output is sent as HTML. Similarly, there is the extension .asmx for SOAP services (based on Webservice) and .ashx for generic "handlers" (based on Ihttphandler).

Finally, the extension .asax is exclusive to Global.asax, because it makes no sense to have more than one application descriptor (which one the server would use?).

0

Hello, from my experience with C#, Global.ASAX serves as a start of your system, is a manager, will manage what happens in case of errors and what you do when you start a debug

0

good morning!

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.