-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: dnyanesh
Message 4 in Discussion




  
    
    New Message on MumbaiUserGroup
  
  





      Question Of The Day !!!! -- (17-10-2005) -- ASP.NET 2.0

    
  
    
      Reply

          
            
                
               
                  Reply to Sender
                    Recommend
                  
                  Message 2 in Discussion
                                                
            
          
        
                    
        
            
              From: 
              dnyanesh
            
            
              

               Hi, Que: Mention the different compilation models available in 
ASP.NET 2.0 ? Ans:  ASP.NET 2.0 Compilation Model
The first thing that needs to be pointed out about the ASP.Net 2.0 model is 
that the complex division of responsibility between the code-behind and the 
ASPX page is removed. Listings 3 and 4 show the ASPX page and the code-behind 
file. Notice that the code-behind file is much cleaner than the ones in ASP.NET 
1.X. The code-behind page just contains the user-defined code. It no longer 
contains all the control declarations that are needed to synchronize the ASPX 
file and the code-behind page in ASP.NET 1.X. In ASP.NET 2.0, the association 
between the ASPX and the code-behind page is specified with a new directive 
called Compilewith shown in the following code snippet:   
<%@ Page Language="C#" CompileWith="Default.aspx.cs" ClassName="Default_aspx" 
%>  
Also, notice a new directive called ClassName, which in this case is 
Default_aspx. This is the name of the class that the page would be given when 
it is compiled. Another interesting point is that the class name of the 
code-behind page is the same as that of the ASPX page. So the obvious question 
is how is it possible to have the same class declaration in two different 
files? This is made possible by the new construct partial class in .NET 
Framework 2.0 that allows a single class to exist in multiple files. In this 
case, when an ASPX page with a new code-behind file is requested, the ASP.NET 
2.0 runtime will actually combine the class definition that is spread in the 
ASPX page and the code-behind page into a single class named Default_aspx. 
Another change that I would like to point out is that the code-behind page no 
longer inherits from System.UI.web.Page and it also no longer needs to define 
all the controls that are defined in the ASPX page. This is because now we are 
dealing with one class, unlike before where we had two different classes with 
one inheriting from the other. Figure 2 shows the inheritance model in ASP.NET 
2.0.Visual Studio 2005 beta no longer pre-compiles all the code-behind pages 
into the project assembly. Because this intermediate step of pre-compilation is 
avoided, there is no need to rebuild the entire project for a single change. 
Another big advantage is that Visual Studio 2005 IDE now provides the same 
level of support Intellisense to a developer who chooses to follow the single 
file model for development.  
New Compilation Features
In ASP.NET 1.X, the two modes of compilation available were either compilation 
on first request of each page or batch compilation where in many temporary ASPX 
pages were compiled into a single assembly. Batch compilation is preferred in 
some scenarios to reduce the delay on the first page request. Listing 5 shows 
how to set up batch compilation in ASP.NET 1.X via the Web.config file. ASP.NET 
2.0 has simplified the batch compilation process and all that is needed is a 
single URL request:  
http://localhost/myapp/precompile.axd  
This mode of compilation is known as in-place compilation. The advantage of 
using in-place compilation is that it helps eliminate the time delay in batch 
compilation on the first request. It also helps to identify the compilation 
errors before the users find them.  
ASP.NET 2.0 supports yet another way for compiling and deploying Web 
applications: full deployment pre-compilation. All the code-behind, ASPX, and 
HTML files are compiled into one or more assemblies or executables. This type 
of compilation helps to protect the intellectual property in the code because 
the ASPX and code-behind files no longer have to be deployed as such on the 
production server. The compiled executable can then be copied to its 
destination via Xcopy or FTP. This model of compilation provides the greatest 
performance and security. However, it comes at a cost because we will not be 
able to modify the Web site once it's deployed. For full deployment 
pre-compilation, we use a command line tool called aspnet_compiler. The result 
of pre-compiling is a site with a bin directory that contains assemblies and a 
number of stub files with the same name as the original pages. However, when 
you open them you will notice that the files contain no code or HTML markup 
inside, although the user will not notice any difference when browsing the Web 
site. The code below shows the command line option to precompile the Web site.  
aspnet_compiler /v /<websitename> -p <source path> <destination>  
<websitename> is the name of the Web site <source path> is the location of the 
Web site to compile, and <destination> is the file path where the compiled 
assemblies have to be deployed.  
The Code Directory
The code directory is another special folder that is used by ASP.NET 2.0. We 
are already familiar with the bin directory where ASP.NET 1.X stores the 
precompiled assemblies. The code folder in ASP.NET 2.0, on the other hand, is 
used to store class files that are to be dynamically compiled at runtime. These 
classes are then automatically referenced by the application that contains the 
code folder. The biggest advantage of using the code directory is that the 
project no longer needs to be built before deployment and the classes also need 
not be referenced. This greatly simplifies the development process. Figure 3 
and Listings 6, 7, and 8 show a very simple example of using the code 
directory. CodeClass.cs is placed in the code directory, and contains a static 
method that returns the string. The Web page assigns the value of the string to 
the label when the button is clicked. Once the CodeClass is placed in the 
directory and the appropriate code is written in the button click method, any 
change to the string in the CodeClass GetLabelText method is reflected on the 
Web site by a simple refresh.  
ASP.NET 2.0 also allows Web developers to set the hierarchy structure of the 
code directory, giving them the freedom to organize the class files in the 
folder. The only requirement is that the topmost-level directory should be 
named ?code? (not case sensitive), and it should be below the application root. 
Listing 9 shows an example of hierarchy inside the code folder.  
These classes are available anywhere in the application folder. All of the code 
that is placed in the code directory is compiled into a single assembly. 
Because of this, all the files in the code folder should belong to a single 
programming language (i.e., they can either be in C# or in VB.NET). However, we 
can configure the Web site to treat different folders in the code folder as 
separate compilable units. This is done by defining a <codeSubDirectories> 
element in the <compilation> element of the Web.config file and adding a 
reference to the subfolder. Listing 10 shows how to define two subfolders in 
the code folder. The names are just for reference. The programming language to 
be used in the folder is no way linked to the directory name.  
  
Regards,
Dnyaneshwar Parkhe
          
        
      
          
  

    View other groups in this category.
  

  

      




-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to