Tuesday, July 19, 2011

ASP.NET FEATURES AND DEVELOPMENT ENVIRONMENT

ASP.NET 
ASP.NET, the next version of ASP, is a programming framework used to create enterprise-class Web Applications. These applications are accessible on a global basis leading to effecient information managment. The advantages ASP.NET offers is more than just the next version of ASP.
Why ASP.NET?
Since 1995, Microsoft has been constantly working to shift it's focus from Windows-based platforms to the Internet. As a result, Microsoft introduced ASP (Active Server Pages) in November 1996. ASP offered the efficiency of ISAPI applications along with a new level of simplicity that made it easy to understand and use. However, ASP scriptwas an interpreted script and consisted unstructured code and was difficult to debug and maintain. As the web consists of many different technologies, software integration for Web development was complicated and required to understand many different technologies. Also, as applications grew bigger in size and became more complex, the number of lines of source code in ASP applications increased dramatically and was hard to maintain. Therefore, an architecture was needed that would allow development of Web applications in a structured and consistent way.
The .NET Framework was introduced with a vision to create globally distributed software with Internet functionality and interoperability. The .NET Framework consists of many class libraries, includes multiple language support and a common execution platform. It's a very flexible foundation on which many different types of top class applications can be developed that do different things. Developing Internet applications with the .NET Framework is very easy. ASP.NET is built into this framework, we can create ASP.NET applications using any of the built-in languages.
Unlike ASP, ASP.NET uses the Common Language Runtime (CLR) provided by the .NET Framework. This CLR manages execution of the code we write. ASP.NET code is a compiled CLR code instead of  interpreted code (ASP). CLR also allows objects written in different languages to interact with each other. The CLR makes developement of Web applications simple.
Advantages Using ASP.NET
  • ASP.NET drastically reduces the amount of code required to build large applications
  • ASP.NET makes development simpler and easier to maintain with an event-driven, server-side programming model
  • ASP.NET pages are easy to write and maintain because the source code and HTML are together
  • The source code is executed on the server. The pages have lots of power and flexibility by this approach
  • The source code is compiled the first time the page is requested. Execution is fast as the Web Server compiles the page the first time it is requested. The server saves the compiled version of the page for use next time the page is requested
  • The HTML produced by the ASP.NET page is sent back to the browser. The application source code you write is not sent and is not easily stolen
  • ASP.NET makes for easy deployment. There is no need to register components because the configuration information is built-in
  • The Web server continuously monitors the pages, components and applications running on it. If it noticies memory leaks, infinite loops, other illegal software or activities, it seamlessly kills those activities and restarts itself
  • ASP.NET validates information (validation controls) entered by the user without writing a single line of code
  • ASP.NET easily works with ADO .NET using data-binding and page formatting features
  • ASP.NET applications run fater and counters large volumes of users without performance problems
Differences between ASP.NET and Client-Side Technologies
Client-side refers to the browser and the machine running the browser. Server-side on the other hand refers to a ASP hosting Web server.
Client-Side Scripting
Javascript and VBScript and generally used for Client-side scripting. Client-side scripting executes in the browser after the page is loaded. Using client-side scripting you can add some cool features to your page. Both, HTML and the script are together in the same file and the script is download as part of the page which anyone can view. A client-side script runs only on a browser that supports scripting and specifically the scripting language that is used. Since the script is in the same file as the HTML and as it executes on the machine you use, the page may take longer time to download.
Server-Side Scripting
ASP.NET is purely server-side technology. ASP.NET code executes on the server before it is sent to the browser. The code that is sent back to the browser is pure HTML and not ASP.NET code. Like client-side scripting, ASP.NET code is similar in a way that it allows you to write your code alongside HTML. Unlike client-side scripting, ASP.NET code is executed on the server and not in the browser. The script that you write alongside your HTML is not sent back to the browser and that prevents others from stealing the code you developed.
ASP.NET Features
ASP.NET is not just a simple upgrade or the latest version of ASP. ASP.NET combines unprecedented developer productivity with performance, reliability, and deployment. ASP.NET redesigns the whole process. It's still easy to grasp for new comers but it provides many new ways of managing projects. Below are the features of ASP.NET.
Easy Programming Model 
ASP.NET makes building real world Web applications dramatically easier. ASP.NET server controls enable an 
HTML-like style of declarative programming that let you build great pages with far less code than with classic ASP.  Displaying data, validating user input, and uploading files are all amazingly easy. Best of all, ASP.NET pages work in all browsers including Netscape, Opera, AOL, and Internet Explorer.

Flexible Language Options  
ASP.NET lets you leverage your current programming language skills.  Unlike classic ASP, which supports only interpreted VBScript and JScript, ASP.NET now supports more than 25 .NET languages (built-in support for VB.NET, C#, and JScript.NET), giving you unprecedented flexibility in your choice of language.
Great Tool Support 
You can harness the full power of ASP.NET using any text editor, even Notepad.  But Visual Studio .NET adds the productivity of Visual Basic-style development to the Web. Now you can visually design ASP.NET Web Forms using familiar drag-drop-doubleclick techniques, and enjoy full-fledged code support including statement completionand color-coding. VS.NET also provides integrated support for debugging and deploying ASP.NET Web applications. The Enterprise versions of Visual Studio .NET deliver life-cycle features to help organizations plan, analyze, design, build, test, and coordinate teams that develop ASP.NET Web applications.  These include UML class modeling, database modeling (conceptual, logical, and physical models), testing tools (functional, performance and scalability), and enterprise frameworks and templates, all available within the integrated Visual Studio .NET environment.
Rich Class Framework 
Application features that used to be hard to implement, or required a 3rd-party component, can now be added in just a few lines of code using the .NET Framework.  The .NET Framework offers over 4500 classes that encapsulate rich functionality like XML, data access, file upload, regular expressions, image generation, performance monitoring and logging, transactions, message queuing, SMTP mail, and much more. With Improved Performance and Scalability ASP.NET lets you use serve more users with the same hardware.
Compiled execution 
ASP.NET is much faster than classic ASP, while preserving the "just hit save" update model of ASP.  However, no explicit compile step is required. ASP.NET will automatically detect any changes, dynamically compile the files if needed, and store the compiled results to reuse for subsequent requests. Dynamic compilation ensures that your application is always up to date, and compiled execution makes it fast.  Most applications migrated from classic 
ASP see a 3x to 5x increase in pages served.

Rich output caching
ASP.NET output caching can dramatically improve the performance and scalability of your application. When output caching is enabled on a page, ASP.NET executes the page just once, and saves the result in memory in addition to sending it to the user.  When another user requests the same page, ASP.NET serves the cached result from memory without re-executing the page. Output caching is configurable, and can be used to cache individual regions or an entire page. Output caching can dramatically improve the performance of data-driven pages by eliminating the need to query the database on every request.
Web-Farm Session State
ASP.NET session state lets you share session data user-specific state values across all machines in your Web farm.  Now a user can hit different servers in the Web farm over multiple requests and still have full access to her session.  And since business components created with the .NET Framework are free-threaded, you no longer need to worry about thread affinity.
Enhanced Reliability
ASP.NET ensures that your application is always available to your users.
Memory Leak, DeadLock and Crash Protection 
ASP.NET automatically detects and recovers from errors like deadlocks and memory leaks to ensure your application is always available to your users.  For example, say that your application has a small memory leak, and that after a week the leak has tied up a significant percentage of your server's virtual memory. ASP.NET will detect this condition, automatically start up another copy of the ASP.NET worker process, and direct all new requests to the new process. Once the old process has finished processing its pending requests, it is gracefully disposed and the leaked memory is released. Automatically, without administrator intervention or any interruption of service, ASP.NET has recovered from the error.   
Easy Deployment
ASP.NET takes the pain out of deploying server applications. "No touch" application deployment. ASP.NET dramatically simplifies installation of your application. With ASP.NET, you can deploy an entire application as easily as an HTML page, just copy it to the server.  No need to run regsvr32 to register any components, and configuration settings are stored in an XML file within the application.
Dynamic update of running application 
ASP.NET now lets you update compiled components without restarting the web server. In the past with classic COM components, the developer would have to restart the web server each time he deployed an update.  With ASP.NET, you simply copy the component over the existing DLL, ASP.NET will automatically detect the change and start using the new code.
Easy Migration Path 
You don't have to migrate your existing applications to start using ASP.NET. ASP.NET runs on IIS side-by-side with classic ASP on Windows 2000 and Windows XP platforms. Your existing ASP applications continue to be processed by ASP.DLL, while new ASP.NET pages are processed by the new ASP.NET engine. You can migrate application by application, or single pages.  And ASP.NET even lets you continue to use your existing classic COM business components. 
XML Web Services 
XML Web services allow applications to communicate and share data over the Internet, regardless of operating system or programming language. ASP.NET makes exposing and calling XML Web Services simple. Any class can be converted into an XML Web Service with just a few lines of code, and can be called by any SOAP client.  Likewise, ASP.NET makes it incredibly easy to call XML Web Services from your application. No knowledge of networking, XML, or SOAP is required.
Mobile Web Device Support 
ASP.NET Mobile Controls let you easily target cell phones, PDAs and over 80 mobile Web devices. You write your application just once, and the mobile controls automatically generate WAP/WML, HTML, or iMode as required by the requesting device. 
 ASP.NET Development Environment 
Most of the programming languages with which we work require a development environment to code, test and run the programs. You may purchase a copy of that software at your local computer store and work with it. With ASP.NET things are different. ASP.NET is a development technology that is built into the .NET Framework. You can create ASP.NET applications with a simple editor like a notepad. If you prefer to work in a development environment then you have many to choose from. Visual Studio .NET (should purchase) is one development environment from Microsoft. Another development environment from Microsoft which is prefered by many developers is Microsoft Web Matrix. The best thing about ASP.NET Web Matrix is it's free (available as a 1.4 MB free download) and provides most of the features Visual Studio .NET provides.
Setting Up the Development Environment
As you already know, ASP.NET is based on the CLR, class libraries and other tools which are integrated into the .NET Framework. To develop and run a ASP.NET application you need to have the .NET Framework installed on your machine. .NET Framework comes pre installed with Operating Systems like Windows 2003 Server and Windows XP. For other operating systems (Windows 2000, 98, Me, NT 4.0) you need to instal the .NET Framework manually. You can install .NET Framework manually in two ways: .NET Framework SDK or VS .NET.
Installing the .NET Framework with SDK is simple. Download .NET Framework from Microsoft.com and
double-click setup file and follow the instructions. Installing .NET Framework with Visual Studio .NET is simple too. When you install Visual Studio .NET (set of five cd's) you will be prompted to insert the disk that contains the .NET Framework.
IIS
To develop a Web Application you need IIS (Internet Information Server) on your machine. IIS comes pre installed in Operating Systems like Windows 2000, XP and 2003. You need to configure IIS to run ASP.NET Web applications. You should configure IIS prior to the installation of Visual Studio .NET software on your machine to avoid errors. In most cases configuring IIS after the installation of VS .NET will result in many errors and unexpected behaviour by the application.
By default, IIS creates a folder on the server's hard drive with the name Inetpub. The Inetpub folder contains a subfolder called wwwroot. The wwwroot folder is the root for the Web site. All the ASP.NET applications you develop using VS .NET are saved in this wwwroot folder.
Web Hosting
You also can test and run your applications on a server owned by hosting providers. The host will give you details you need to know to upload files onto his server, test those files, etc. Web Hosting providers charge some amount for providing service. There are some hosting providers who provide some space for a certain period of time on their servers for ASP.NET developers to test their applications free of charge. You can find about them on the resources page of this site.
Visual Studio .NET
Visual Studio .NET consists of five cd's. Please follow the guide lines on installing the software.
ASP.NET Web Matrix
To use Web Matrix you need to download Web Matrix software which is a small 1.4 MB file and run the installation. To use Web Matrix you should have the .NET Framework installed on your machine. Developers who decide to code their applications using ASP .NET Web matrix need not worry about IIS. Web Matrix server comes with it's own built-in server that helps you to test and run your applications.
Database
To develop ASP.NET database applications you need to install SQL Server 2000 or higher or Oracle depending on the database you wish to use. Use of SQL Server with ASP.NET is recommended as it's said that SQL Connections are 70% faster than OLEDB Connections. Also, performance improves dramatically when you use SQL Server with ASP.NET.
Web Forms
Web Forms are based on ASP.NET. Working with Web Forms is similar to working with Windows Forms. But the difference is that we will create Web pages with Web formsthat will be accessible by a Web browser. Web Forms are Web pages that serve as the user interface for a Web application. A Web Forms page presents information to the user in any browser or client device and implements application logic using server-side code. Web Forms are based on the System.Web.UI.Page class. The class hierarchy for the page class is shown below.

 Object
  Control
   TemplateControl
    Page

Components of Web Forms
In Web Forms pages, the user interface programming is divided into two parts: the visual component (design page) and the logic (code behind page).
The visual element is the Web Forms page. The page consists of a file with static HTML, or ASP.NET server controls, or both simultaneously. The Web Forms page works as a container for the static text and the controls we want to display. Using the Visual Studio Web Forms Designer and ASP.NET server controls, we can design the form just like in any Visual Studio application.
The logic for the Web Forms page consists of code that we create to interact with the form. The programming logic is in a separate file from the user interface file. This file is the "code-behind" file and has an ".aspx.vb" (VB) or ".aspx.cs" (C-Sharp) extension. The logic we write in the code-behind file can be written in Visual Basic or Visual C#.
The code-behind class files for all Web Forms pages in a project are compiled into the project dynamic-link library (.dll) file. The .aspx page file is also compiled, but differently. The first time a user loads the aspx page, ASP.NET automatically generates a .NET class file that represents the page, and compiles it to a second .dll file. The generated class for the aspx page inherits from the code-behind class that was compiled into the project .dll file. When the user requests the Web page URL, the .dll filesrun on the server and dynamically produces the HTML output for your page

Web Forms Page Life Cycle 
In general, the life cycle for a Web Forms page is similar to that of any Web process that runs on the server. Certain characteristics of Web processing information is passed via HTTP protocol, the stateless nature of Web pages, and so on. However, the ASP.NET page framework performs many Web application services for us. It is important to understand the sequence of events that occur when a Web Forms page is processed.
The Life Cycle of a Web Forms Page
It will be helpful to understand some fundamental characteristics of how Web Forms pages work in Web applications before we examine the details of what goes on inside a page when it is processed.
Round Trips
Most Web pages require processing on the server. For example, consider a products page used to check the availability of a certain product. When a user selects his product and hits the submit button the page must check on the server to see whether the selected product is available or not. This kind of functionality is achieved by handling server control events. Whenever a user interaction requires processing on the server, the Web page is posted back to the server, processed and is returned back to the browser. This sequence is called round trip. The image below demonstrates server round trip.

Server Round Trip
In any Web scenario, Web pages are recreated with every round trip. When the server finishes processing and sends the page to the browser, it discards the page information. This frees server resources after each request and a Web application can scale to support hundreds or thousands of simultaneous users. The next time the page is posted, the server starts over in creating and processing it, and for this reason, Web pages are said to be stateless. Stateless means the values of a page's variables and controls are not saved on the server.
ASP.NET works around the above said limitations in the following ways:
  • ASP.NET saves page and control properties between round trips. This is referred to as saving the view state of the control
  • It provides state management facilities so that you can save your own variable and application-specific or session-specific information between round trips. 
  • It can detect when a form is requested for the first time versus when the form is posted, and allows you to program accordingly. You may want a different behavior during a page postback versus an initial request.
Stages in Web Forms Processing

StageMeansUse
Page InitializationThe page's Page_Init event is raised, and the page and control view state are restored.During this event, the ASP.NET page framework restores the controlproperties and postback data.
User Code InitializationThe page's Page_Load event is raised.Read and restore values stored previously, Using the Page.IsPostBack property, check whether this is the first time the page is being processed. If this is the first time the page is being processed then perform initial data binding. Otherwise, restore control values. Read and update control properties.
ValidationThe Validate method of any validator Web server controls is invoked to perform the control's specified validation.Test the outcome of validation in an event handler
Event HandlingIf the page was called in response to a form event, the corresponding event handler in the page is called during this stagePerform application-specific processing and handle the specific event raised.
CleanupThe Page_Unload event is called because the page has finished rendering and is ready to be discarded.Perform final cleanup work. Close files, closing database connections and discard objects.

No comments:

Post a Comment