What happens when the default.aspx page is requested for the first time?

advertisements

What happens when default.aspx page is requested for the first time?

.net is pure a pure Object Oriented Framework.

_default is a class which extends Page.

Without instantiating, Pre-Init,Init,Load cannot be called. So How _default class is instantiated? Who is responsible for that?

I want to know very detailed technical steps?

Pleasa clarify!


The ASP.Net framework identifies that the request is for the page default.aspx and examines the markup of the corresponding .aspx file - using this it generates a class based on that markup. The base class for that class is identified in the @Page directive:

<%@ Page ... Inherits="WebApplication1._Default" %>

It then creates an instance of that generated type - this type inherits from the given base class, in this case WebApplication1._Default.

The ASP.Net framework doesn't normally (ever?) directly create an instance of your "code behind" class.

You can see this for yourself by debugging a simple web application:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // default_asp NOT _Default as you might expect
        string typeName = this.GetType().Name;
    }
}

This explains why event handlers only need to be marked as protected instead of public.

If you are really keen you can get the path to the generated assembly using this.GetType().Assembly.CodeBase, make a copy of that file and inspect the generated class in something like IL Spy.