Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Gauge for SharePoint
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » ASP.NET 2.0 » Coding Model and Compilation in ASP.NET 2.0

Coding Model and Compilation in ASP.NET 2.0

This article explains about differences between different coding models and the compilation techniques of ASP.NET pages.

Page Views : 9894
Downloads : 0
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Nevron Gauge for SharePoint
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

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

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Santhi Maadhaven
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.