|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionI have seen many tutorials on ASP.NET but most of them starts with coding and writing your first ASP.NET Program. But here I has written this tutorial for explaining why there is a need for ASP.NET when classy ASP is working fine and what are the underlying technology behind ASP.NET, What programming model ASP.NET Provides to programmers. Now let us get started. ASP.NET is the new offering for Web developers from the Microsoft .It is not simply the next-generation of ASP; in fact, it is a completely re-engineered and enhanced technology that offers much, much more than traditional ASP and can increase productivity significantly. Because it has evolved from ASP, ASP.NET looks very similar to its predecessor—but only at first sight. Some items look very familiar, and they remind us of ASP. But concepts like Web Forms, Web Services, or Server Controls gives ASP.NET the power to build real Web applications. Looking Back : Active Server Pages (ASP)Microsoft Active Server Pages (ASP) is a server-side scripting technology. ASP is a technology that Microsoft created to ease the development of interactive Web applications. With ASP you can use client-side scripts as well as server-side scripts. Maybe you want to validate user input or access a database. ASP provides solutions for transaction processing and managing session state. Asp is one of the most successful language used in web development. Problems with Traditional ASPThere are many problems with ASP if you think of needs for Today's powerful Web applications.
Introducing ASP.NETASP.NET was developed in direct response to the problems that developers had with classic ASP. Since ASP is in such wide use, however, Microsoft ensured that ASP scripts execute without modification on a machine with the .NET Framework (the ASP engine, ASP.DLL, is not modified when installing the .NET Framework). Thus, IIS can house both ASP and ASP.NET scripts on the same machine. Advantages of ASP.NET
ASP.NET OverviewHere are some point that gives the quick overview of ASP.NET.
ASP.NET ArchitectureASP.NET is based on the fundamental architecture of .NET Framework. Visual studio provide a uniform way to combine the various features of this Architecture.
Architecture is explained form bottom to top in the following discussion.
Quick Start :To ASP.NETAfter this short excursion with some background information on the .NET Framework, we will now focus on ASP.NET. File name extensionsWeb applications written with ASP.NET will consist of many files with different file name extensions. The most common are listed here. Native ASP.NET files by default have the extension .aspx (which is, of course, an extension to .asp) or .ascx. Web Services normally have the extension .asmx. Your file names containing the business logic will depend on the language you use. So, for example, a C# file would have the extension .aspx.cs. You already learned about the configuration file Web.Config. Another one worth mentioning is the ASP.NET application file Global.asax - in the ASP world formerly known as Global.asa. But now there is also a code behind file Global.asax.vb, for example, if the file contains Visual Basic.NET code. Global.asax is an optional file that resides in the root directory of your application, and it contains global logic for your application. All of these are text filesAll of these files are text files, and therefore human readable and writeable. The easiest way to startThe easiest way to start with ASP.NET is to take a simple ASP page and change the file name extension to .aspx. Page SyntaxHere is quick introduction of syntax used in ASP.NET DirectivesYou can use directives to specify optional settings used by the page compiler when processing ASP.NET files. For each directive you can set different attributes. One example is the language directive at the beginning of a page defining the default programming language. Code Declaration BlocksCode declaration blocks are lines of code enclosed in <script> tags. They contain the runat=server attribute, which tells ASP.NET that these controls can be accessed on the server and on the client. Optionally you can specify the language for the block. The code block itself consists of the definition of member variables and methods. Code Render BlocksRender blocks contain inline code or inline expressions enclosed by the character sequences shown here. The language used inside those blocks could be specified through a directive like the one shown before. HTML Control SyntaxYou can declare several standard HTML elements as HTML server controls. Use the element as you are familiar with in HTML and add the attribute runat=server. This causes the HTML element to be treated as a server control. It is now programmatically accessible by using a unique ID. HTML server controls must reside within a <form> section that also has the attribute runat=server. Custom Control SyntaxThere are two different kinds of custom controls. On the one hand there are the controls that ship with .NET, and on the other hand you can create your own custom controls. Using custom server controls is the best way to encapsulate common programmatic functionality. Just specify elements as you did with HTML elements, but add a tag prefix, which is an alias for the fully qualified namespace of the control. Again you must include the runat=server attribute. If you want to get programmatic access to the control, just add an Id attribute. You can include properties for each server control to characterize its behavior. For example, you can set the maximum length of a TextBox. Those properties might have sub properties; you know this principle from HTML. Now you have the ability to specify, for example, the size and type of the font you use (font-size and font-type). The last attribute is dedicated to event binding. This can be used to bind the control to a specific event. If you implement your own method Data Binding ExpressionYou can create bindings between server controls and data sources. The data binding expression is enclosed by the character sequences <%# and %>. The data-binding model provided by ASP.NET is hierarchical. That means you can create bindings between server control properties and superior data sources. Server-side Object TagsIf you need to create an instance of an object on the server, use server-side object tags. When the page is compiled, an instance of the specified object is created. To specify the object use the identifier attribute. You can declare (and instantiate) .NET objects using class as the identifier, and COM objects using either progid or classid. Server-side Include DirectivesWith server-side include directives you can include raw contents of a file anywhere in your ASP.NET file. Specify the type of the path to filename with the pathtype attribute. Use either File, when specifying a relative path, or Virtual, when using a full virtual path. Server-side CommentsTo prevent server code from executing, use these character sequences to comment it out. You can comment out full blocks - not just single lines. First ASP.NET Program.Now let us have our First ASP.NET program. Let’s look at both the markup and the C# portions of a simple web forms application that generates a movie line-up dynamically through software. Markup PortionWeb form application part 1 -- SimpleWebForm.aspx<% @Page Language="C#" Inherits="MoviePage" Src="SimpleWebForm.cs" %>
<html>
<body background="Texture.bmp">
<TITLE>Supermegacineplexadrome!</TITLE>
<H1 align="center"><FONT color="white" size="7">Welcome to
And this is where the C# part of a web forms application comes in. Web form application part 2 - SimpleWebForm.csusing System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class MoviePage:Page
{
protected void WriteDate()
{
Response.Write(DateTime.Now.ToString());
}
protected void WriteMovies()
{
Response.Write("<P>The Glass Ghost (R) 1:05 pm, 3:25 pm, 7:00 pm</P>");
Response.Write("<P>Untamed Harmony (PG-13) 12:50 pm, 3:25 pm, " +
Execution Cycle :Now let's see what’s happening on the server side. You will shortly understand how server controls fit in. A request for an .aspx file causes the ASP.NET runtime to parse the file for code that can be compiled. It then generates a page class that instantiates and populates a tree of server control instances. This page class represents the ASP.NET page. Now an execution sequence is started in which, for example, the ASP.NET page walks its entire list of controls, asking each one to render itself. The controls paint themselves to the page. This means they make themselves visible by generating HTML output to the browser client. Execution ProcessWe need to have a look at what’s happening to your code in ASP.NET. Compilation, when page is requested the first timeThe first time a page is requested, the code is compiled. Compiling code in .NET means that a compiler in a first step emits Microsoft intermediate language (MSIL) and produces metadata—if you compile your source code to managed code. In a following step MSIL has to be converted to native code. Microsoft intermediate language (MSIL)Microsoft intermediate language is code in an assembly language–like style. It is CPU independent and therefore can be efficiently converted to native code. The conversion in turn can be CPU-specific and optimized. The intermediate language provides a hardware abstraction layer. MSIL is executed by the common language runtime. Common language runtimeThe common language runtime contains just-in-time (JIT) compilers to convert the MSIL into native code. This is done on the same computer architecture that the code should run on. The runtime manages the code when it is compiled into MSIL—the code is therefore called managed code. ASP.NET Applications and ConfigurationOverviewLike ASP, ASP.NET encapsulates its entities within a web application. A web application is an abstract term for all the resources available within the confines of an IIS virtual directory. For example, a web application may consist of one or more ASP.NET pages, assemblies, web services configuration files, graphics, and more. In this section we explore two fundamental components of a web application, namely global application files (Global.asax) and configuration files (Web.config). Global.asaxGlobal.asax is a file used to declare application-level events and objects. Global.asax is the ASP.NET extension of the ASP Global.asa file. Code to handle application events (such as the start and end of an application) reside in Global.asax. Such event code cannot reside in the ASP.NET page or web service code itself, since during the start or end of the application, its code has not yet been loaded (or unloaded). Global.asax is also used to declare data that is available across different application requests or across different browser sessions. This process is known as application and session state management. The Global.asax file must reside in the IIS virtual root. Remember that a virtual root can be thought of as the container of a web application. Events and state specified in the global file are then applied to all resources housed within the web application. If, for example, Global.asax defines a state application variable, all .aspx files within the virtual root will be able to access the variable. Like an ASP.NET page, the Global.asax file is compiled upon the arrival of the first request for any resource in the application. The similarity continues when changes are made to the Global.asax file; ASP.NET automatically notices the changes, recompiles the file, and directs all new requests to the newest compilation. A Global.asax file is automatically created when you create a new web application project in the VS.NET IDE. Application DirectivesApplication directives are placed at the top of the Global.asax file and provide information used to compile the global file. Three application directives are defined, namely Application, Assembly, and Import. Each directive is applied with the following syntax: <%@ appDirective appAttribute=Value ...%>
Web.configIn ASP, configuration settings for an application (such as session state) are stored in the IIS metabase. There are two major disadvantages with this scheme. First, settings are not stored in a human-readable manner but in a proprietary, binary format. Second, the settings are not easily ported from one host machine to another.(It is difficult to transfer information from an IIS’s metabase or Windows Registry to another machine, even if it has the same version of Windows.) Web.config solves both of the aforementioned issues by storing configuration information as XML. Unlike Registry or metabase entries, XML documents are human-readable and can be modified with any text editor. Second, XML files are far more portable, involving a simple file transfer to switch machines. Unlike Global.asax, Web.config can reside in any directory, which may or may not be a virtual root. The Web.config settings are then applied to all resources accessed within that directory, as well as its subdirectories. One consequence is that an IIS instance may have many web.config files. Attributes are applied in a hierarchical fashion. In other words, the web.config file at the lowest level directory is used. Since Web.config is based on XML, it is extensible and flexible for a wide variety of applications. It is important, however, to note that the Web.config file is optional. A default Web.config file, used by all ASP.NET application resources, can be found on the local machine at: \%winroot%\Microsoft.Net\Framework\version\CONFIG\machine.config SummaryASP.NET is an evolution of Microsoft’s Active Server Page (ASP) technology. Using ASP.NET, you can rapidly develop highly advanced web applications based on the .NET framework. Visual Studio Web Form Designer, which allows the design of web applications in an intuitive, graphical method similar to Visual Basic 6. ASP.NET ships with web controls wrapping each of the standard HTML controls, in addition to several controls specific to .NET. One such example is validation controls, which intuitively validate user input without the need for extensive client-side script. In many respects, ASP.NET provides major improvements over ASP, and can definitely be considered a viable alternative for rapidly developing web-based applications. Points of InterestI has write this tutorial to share my Knowledge of ASP.NET with you. You can find more articles and software projects with free source code on my web site http://programmerworld.net . History
| ||||||||||||||||||||