Using ASP.NET

In 2002, Microsoft released the .NET Framework, and a new way to write applications was born. The .NET Framework provides a common framework that developers can use to create Windows applications, Web applications, and XML Web services. In order to run ASP.NET on a Web server, the Web server must be IIS version 5 or greater, and it must have the .NET Framework installed on it. This means that you must have Windows 2000 or greater.

NOTE

Windows XP Home Edition cannot run ASP or ASP.NET pages because it does not support the installation of a Web server. If you want to test the ASP or ASP.NET pages you develop on Windows XP, you must use Windows XP Professional Edition. You can develop ASP or ASP.NET pages on Windows XP Home Edition, but before they can be browsed, they must be published to a Web server that supports the technology you're using.


The Common Language Runtime

An application written using the .NET Framework runs under Common Language Runtime. When a developer writes software using the .NET Framework, she compiles her program into intermediate code known as Microsoft Intermediate Language or MSIL, which is code that only the Common Language Runtime understands. When someone runs that software, the MSIL code is compiled again into executable code that the operating system can run in a process known as Just In Time compilation, or JIT.

For more information on the Microsoft .NET Framework including XML Web Services, the Common Language Runtime, MSIL, and JIT compilation, read Think Microsoft.NET from Que Publishing.


Microsoft released a version of the Common Language Runtime in combination with the .NET Framework release and the release of Visual Studio .NET. The current Common Language Runtime runs on Windows machines, but work is underway by independent software developers to develop a version of the Common Language Runtime that will run on Unix or Linux machines as well. Because of the way Microsoft designed the .NET Framework, once a version of the Common Language Runtime is developed for another operating system, developers will simply have to compile their code on the new operating system and then they will be able to run applications originally written to run on Windows. If everything works as it should, no code will have to be rewritten. There are exceptions to this, such as those situations in which an application was written to take advantage of Windows-specific functionality.

How ASP.NET Applications Are Developed

ASP.NET is the latest version of Microsoft server-side Web application development technology, and it runs on the .NET Framework. An ASP.NET application is not made up of inline script in a Web page. Instead, ASP.NET is a full-featured development technology, and ASP.NET applications are written following the same principles used when building a Windows application. Instead of VBScript or JScript, ASP.NET developers use VB.NET or C# to develop their applications.

ASP.NET offers many advantages over the legacy ASP application model. A few of the more prominent advantages are

  • Familiar programming approach for developers who aren't used to writing Web applications

  • Full-featured development environment as opposed to a simple scripting language

  • ASP.NET server-controls that provide robust built-in functionality

  • Complete separation of user-interface and server-side code if desired

  • Extremely powerful and flexible control for caching of data

NOTE

Microsoft provides two applications that were specifically designed for developing ASP.NET applications Visual Studio .NET and Web Matrix. Visual Studio .NET is a professional-level suite of tools for developers, whereas Web Matrix is a free ASP.NET development tool that is similar to a very basic and stripped down version of Visual Studio .NET. FrontPage 2003 supports ASP.NET and can generate ASP.NET code in addition to performing rudimentary editing of existing ASP.NET content, but it is not the best choice for designing ASP.NET sites from scratch.


For more information on Visual Studio .NET, read Sams Teach Yourself Visual Studio .NET 2003 from Sams Publishing.


For more information on Web Matrix, see "Front and Center: Developing ASP.NET with Web Matrix" at the end of this chapter.


For more information on using FrontPage to develop ASP.NET pages, see "FrontPage and Databases," p. 705.


Using ASP.NET Server Controls

ASP.NET ships with many server controls that make adding functionality to a Web page very easy. Because these controls are server controls, they run on the Web server and the Web server generates the HTML necessary for the control to be rendered on the Web page. It also means that you can programmatically access these controls in your ASP.NET code.

Listing 35.2 shows a page with an ASP.NET Label server control.

Listing 35.2 A Simple ASP.NET Page
 <%@ Page Language="vb" Codebehind="sample.aspx.vb" Inherits="jcaApp.sample"%> <HTML> <BODY> <asp:Label  runat="server">Current Time</asp:Label> </BODY> </HTML> 

The only part of this page that resembles ASP code is the first line. That line is called the page directive, and it tells ASP.NET what language to use for the page (either vb for VB.NET or c# for C#), what file contains the server-side code (the code that provides most of the page's functionality) if necessary, and what class the page is inherited from. Classes and inheritance are important concepts in ASP.NET. A class is a component of code that stores certain information about itself (called properties) and knows how to perform certain tasks (called methods). In the page in Listing 35.2, the class is called jcaApp.sample, and it is defined in the file sample.aspx.vb.

The sample.aspx.vb file is called the code behind file. This is the means by which ASP.NET allows you to separate the user-interface from the server-side implementation. The code behind file contains all the ASP.NET code for your Web page. To access one of the controls on the Web page from the code behind file, you use the control's id attribute.

Listing 35.3 shows The code behind file for the page in Listing 35.2.

Listing 35.3 The Code Behind File
 Public Class sample     Inherits System.Web.UI.Page     Protected WithEvents lblTime As System.Web.UI.WebControls.Label     Private Sub Page_Load(ByVal sender As System.Object, _       ByVal e As System.EventArgs) Handles MyBase.Load         lblTime.Text = Now.ToLongTimeString     End Sub End Class 

The first and last lines of Listing 35.3 show that the code is defining a class called sample. The next line indicates that the sample class inherits the System.Web.UI.Page class. This is a class that is included with ASP.NET, and it contains many properties and methods that are specific to Web pages. (The Page_Load event that is listed is an example of a method that is included in the System.Web.UI.Page class.) Next is the line that creates the server-side Label control in the code behind page. Note that the name of this control in Listing 35.3 is lblTime just as it is in Listing 35.2. Finally, the Page_Load event indicates what code is to run when the page is loaded by the Web server. In this case, we are setting the Text property of the lblTime Label to the current time.

The server controls included with ASP.NET are contained in a special folder installed by the .NET Framework called the Global Assembly Cache, or GAC. ASP.NET will automatically see these controls without you having to specify any additional configuration settings because it's designed to always look in the GAC for controls and other classes. If you have some controls in other folders on your hard drive that you would like FrontPage to include in your ASP.NET pages, select Tools, Options and click the ASP.NET tab to access the dialog box shown in Figure 35.3. From this dialog box, you can choose a folder for additional ASP.NET controls for all Web pages or for Web pages in the current Web site.

Figure 35.3. The ASP.NET tab on the Options dialog box in FrontPage gives you the ability to specify folders for additional ASP.NET controls.

graphics/35fig03.gif

For complete coverage of programming ASP.NET pages with VB.NET, check out ASP.NET By Example from Que Publishing.


Compiling ASP.NET Applications

Before you can run this ASP.NET page on a Web server, it has to be compiled. This is the process of creating a DLL file that contains all the programming code for the page. That DLL file and the Web page containing the HTML code are then copied to the Web server, and the page is ready to run.

NOTE

The fact that you can compile your ASP.NET code in to a DLL file is another huge advantage over traditional ASP applications. By compiling your code in to a DLL file, you can keep it secure from other people. The code behind file that contains the server-side code for your Web page is not required to be present on the Web server when the page is being browsed.

You can also write your ASP.NET code inline with the HTML page. If you choose that route, the application does not have to be compiled prior to browsing. Instead, it is automatically compiled the first time it is browsed.


When the page is run, the current time on the Web server is printed to the browser window.



Special Edition Using Microsoft Office FrontPage 2003
Special Edition Using Microsoft Office FrontPage 2003
ISBN: 0789729547
EAN: 2147483647
Year: 2003
Pages: 443

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net