Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Coding Model and Compilation in ASP.NET 2.0

Îåêßíçóå áðü ôï ìÝëïò Antonios Chatzipavlis. Τελευταία δημοσίευση από το μέλος George J. Capnias στις 04-06-2005, 02:22. Υπάρχουν 1 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  03-06-2005, 11:09 2431

    Sleep [S] Coding Model and Compilation in ASP.NET 2.0

    Coding Model:

    In ASP.NET 1.x you can develop an ASP.NET page in two ways. First, you put code directly inline with your ASP.NET tags. This code inline model is very similar to the ASP coding model and other scripting languages. This model has several problems such as intermixing of code and HTML. ASP.NET 1.0 introduced code-behind as a replacement. It seperated code from content with issues such as inheritance and keep track of two files for each web page.

    ASP.NET 2.0 still supports this two models with some changes...

    Code Inline:

    The Code inline model is now the default model for Visual Studio 2005.Any code you add to the page will automatically be added to a <script> block within the ASPX file instead of to a code behind class. However, Visual studio 2005 still displays the code in the code view except that code will be placed directly in the ASPX page instead of a separate class.

    Code Behind:

    Difference between a code-behind file in ASP.NET 1.x and ASP.NET2.0 is that a code-behind file is now a partial class rather than a full class that inherits from the ASPX page. A Partial class is a new .NET construct that allows you to define a single class in multiple source files. Partial classes remove the inheritance relationship that is present with the older code behind model.

    Code Behind Models (ASP.NET 1.x and ASP.NET 2.0)

    The two partial classes (ASPX and Code Behind) are merged into a single class during compilation. The code behind file is therefore free of all control declarations and inheritance issues associated with the old code-behind model. Code behind file will no longer contains auto-generated code that used to be necessary to maintain the inheritance relationship.

    Old Code-behind File (ASP.NET 1.x):

    public class WebForm1 : System.Web.UI.Page
    {
    protected
    System.Web.UI.WebControls.Label Label1;
    private void Page_Load(object
    sender, System.EventArgs e) { }
    #region
    Web Form Designer generated code
    override protected void
    OnInit(EventArgs e)
    {
    InitializeComponent();
    base
    .OnInit(e);
    }
    private void
    InitializeComponent()
    {
    this.Load += new System.EventHandler(this
    .Page_Load);
    }
    #endregion
    void Page_Load(object
    sender, EventArgs e)
    {
    Label1.Text = "Hello World";
    }
    }

    New Code Behind File (ASP.NET 2.0):

    namespace Sample
    {
    public partial class
    Webform1_aspx
    {
    void Page_Load(object
    sender, EventArgs e)
    {
    Label1.Text = "Hello World";
    }
    }
    }

    New Code Behind file is cleaner and much easier to read .The code behind files has access to any controls declared on the ASP.NET Page and Visual Studio 2005 provides automatic intellisense support and synchronisation.

    Compilation:

    In ASP.NET 1.x ,application are compiled on first request or in a batch mode on startup. The disadvantage is we had to deploy uncompiled code into our production server. ASP.NET 2.0 offers new compilation method that precompiles source code into binary assemblies for deployment. Pre-Compiled application consists of assemblies ,resources which of no value for an attacker. PreCompiled application is more secure than an normal ASP.NET application. We will see both version models.

    Compilation in ASP.NET 1.x:

    The compilation model in ASP.NET is resulted in one application assembly (contains all the compiled code behind files and other source code) and one temporary assembly created for each aspx request. Using batching may cause temporary assembly to be compiled into the same assembly.

    Disadvantages of this model:

    • Uncompiled code to be deployed in production server which is not secure.
    • First time anyone requests the page, response will be slower than normal as ASP.NET runtime has to compile ASPX page.



    The only control developer has is whether to compile in batch mode or not. we can configure to run in batch mode in web.config's <compilation> section.

    Benefits of batch compilation is reduced load time for the first time and all the aspx pages will be compiled into single temporary file rather than one temporary file for each page.

    Compilation in ASP.NET 2.0:

    ASP.NET 2.0 offers three compilaton models.

    • Normal (ASP.NET 1.x model)

      Code behind files are compiled into assembly and stored in the /bin directory. ASPX files are compiled on demand.

    • Deployment Pre-Compilation

      This is the new feature of ASP.NET 2.0 allows for full compilation of your project prior to deployment. In the full compilation, all code-behind files, aspx pages, HTML, graphic resources and other back-end cide are compiled into one or more executable assemblies. This compilation method provides greatest performance and security but disallows ability to modify the web site post-deployment. This compilation is suitable for highly secure web sites. This will not be suitable for a site which changes frequently.

    • Full runtime Compilation

      ASP.NET 2.0 provides a new mechanism to compile the entire application at runtime. You can put your uncompiled code-behind files and any other associated code in the new \app-code directory and let ASP.NET 2.0 create and maintain references to the assembly that will be generated from these files at runtime. This option provides flexibility in terms of changing the web site content .

    Choosing the compilation model depends on your exact circumstances and needs, but the compilation model remains flexible.

    Hope you will find this article useful and one more thing Microsoft always makes our life easier. Good Day...

    References:

    http://msdn.microsoft.com/asp.net/beta2


    Antonios Chatzipavlis

  •  04-06-2005, 02:22 2462 σε απάντηση της 2431

    Re: Coding Model and Compilation in ASP.NET 2.0

    Κατευθείαν στο ψητό, Αντώνη!

    Πρώτος! Yes


    George J.


    George J. Capnias: Χειροπρακτικός Υπολογιστών, Ύψιστος Γκουράρχης της Κουμπουτερολογίας
    w: capnias.org, t: @gcapnias, l: gr.linkedin.com/in/gcapnias
    dotNETZone.gr News
Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems