Anda di halaman 1dari 10

Joe Martin Brett Tomsom

Teach Yourself

ASP.NET
in

24

Hours
0-672-32126-2

201 West 103rd St., Indianapolis, Indiana, 46290 USA

HOUR

1
This material is not for distributionunedited draft material.

Getting Started with ASP.NET


ASP.NET is a new Internet programming technology from Microsoft that applies a more streamlined, object-oriented approach to building dynamic Web applications. With existing Active Server Pages technology, server-side code is intermingled and interspersed with client-side HTML. This often results in large, complex pages of code, where following the logic of the program can be difficult at best, especially if you are new to programming. In this hour, you will learn more about what ASP.NET has to offer. To be more specific, you will learn: What ASP.NET is What the system requirements are to implement an ASP.NET application

Hour 1

How to install the ASP.NET Framework on your system What tools can be used to create ASP.NET applications How to create an ASP.NET page How to view the output of your ASP.NET pages

What Is ASP.NET?
In the early days of Internet Web site design and development, technologies were limiting. Static HTML pages served up the necessary information that a person wished to convey to his audience. Because technologies were more limiting back then, it was easier to get away with a site that was not as interactive as it needed to be. Nowadays, however, it is important to learn how to build dynamic, interactive Web sites, especially with the increasing use of multimedia elements such as Flash and Shockwave and the development of e-commerce and e-business sites that require database integration. To meet this need, Microsoft created a Web-development platform called Active Server Pages, or ASP. ASP was widely used and accepted throughout the industry because most developers could utilize their existing Visual Basic or VBScript skill sets when developing Web applications. Despite this widespread acceptance, using Active Server Pages was limiting in some respects. For example, validation of form data sometimes required extensive coding on both the client browser and the server. Also, some aspects of Active Server Pages were not scalable in an enterprise environment and didnt function robustly in high-volume sites (although there were ways around these problems). In addition, combining serverside code on the same page as HTML and JavaScript often resulted in Web pages that were a convoluted mixture of server-side logic code and fancy HTML code designed for the user interface, which among other problems made code maintenance a real issue. To overcome these problems and many others, Microsoft has introduced ASP.NETits next-generation Web development environment. If you have experience in programming applications, you will find that the ASP.NET Framework is very similar to building client/server applications. Even if youve never written a line of code in your life, you will find that ASP.NET is a relatively easy programming language to learn.

Is ASP.NET Browser Specific?


ASP.NET is a browser-independent programming model. ASP.NET will run on the latest versions of Internet Explorer and Netscape Navigator, as well as on other widely used browsers, such as Opera. Also, ASP.NET applications will gracefully downgrade to older versions of Internet Explorer and Netscape Navigator. This means that the vast majority

Getting Started with ASP.NET

of users on the Internet will be able to use your Web applications without you needing to write browser-specific code. This feature takes a great burden off the shoulders of current Web developers, although it is still important to be aware that not all browsers accept Dynamic HTML (DHTML) in the same way. For instance, Netscape Navigator versions 4.0 through 4.75 do not allow text on the page to be changed unless the page is reloaded in the browser. Internet Explorer versions 4.0 and higher, on the other hand, do allow text to be changed on the page. These inconsistencies, and many others, still need to be considered when writing client-side code.

What Programming Languages Can Be Used with ASP.NET?


The .NET Framework specifies that applications can be written in any programming language that supports the Common Language Runtime (CLR). The Common Language Runtime translates any CLR-compliant application to Microsoft Intermediate Language (IL). This intermediate-level code is then compiled for the platform where it will be executed. This simple process allows you to create an application in one language that can be used on any operating system using CLR. Furthermore, you can take an application that is written in one programming language and use it in an application that is written in a completely different programming language. No longer do you have to learn a completely different programming language whenever a new technology is released. For the first release of the .NET Framework, Microsoft is releasing four different languages that can be used to write CLR-specific code. These languages are Visual Basic.NET (also known as VB.NET), C# (pronounced C-sharp), C++.NET, and JScript.NET. More languages are expected to join the list as the technology becomes more prevalent. Heres a brief description of each of these languages: Visual Basic.NET: VB.NET is a relatively easy programming language to learn. It is considered a high-level programming language, which means that its syntax is close to human languages and not similar to machine languages, such as Assembly. Of the programming languages mentioned in this section, VB.NET is probably one of the easiest languages to learn. For this reason, all the code examples in this book will be written in VB.NET. C#.NET: C# is a simple, modern, object-oriented, type-safe programming language derived from C and C++. C# aims to combine the high productivity of Visual Basic and the raw power of C++. This language is geared toward more accomplished developers who are used to the somewhat-cryptic structure of C++. Beginning developers are advised to start with Visual Basic and then move on to C#.

Hour 1

Visual C++.NET: Visual C++.NET is the next iteration of Microsofts existing Visual C++ programming language, which is a powerful, object-oriented programming language. Typically, this language is used to create very complex and sophisticated applications. JScript.NET: JScript is a powerful scripting language targeted specifically at the Internet. It is also the first scripting language to fully conform to ECMAScript the Webs only standard scripting language. This language is similar in syntax to C# and C++, although it is a little easier to implement.

What Is Needed to Run ASP.NET?


In order to run ASP.NET pages, you will need to configure a computer with the .NET Framework installed. As of this writing, the .NET Framework is supported on Win9X, Me, NT 4.0, and all versions of Windows 2000. However, Windows NT 4.0 with Service Pack (SP) 6 or Windows 2000 with SP 1 is strongly recommended. You will also need to install Internet Explorer 5.5 and Microsoft Data Access Components (MDAC) 2.6 as prerequisites to the .NET Framework. In addition, if you are not running Windows 2000, you must install Internet Information Server (IIS), known as Personal Web Server (PWS) in Win9X and Me. IIS 5.0 could be easily added to Windows 2000 Professional via Add/Remove Windows Components in the Control Panel. Make sure the IIS service has been started.

Configuring Internet Information Server 5.0


In order to configure IIS 5.0 for ASP.NET, you have to start by creating a virtual directory; to do this, follow these steps (note that we will use IIS 5.0 on Windows 2000 to host all the examples in this book):

, TO DO ,

1. Click the Start button and choose Programs, Administrative Tools, Internet Services Manager. 2. Click the Web server name. On the right side of the screen, Default Web Site should have a status of Running. If this is not the case, highlight Default Web Site by clicking it and then click the Play icon on the toolbar at the top. 3. Clicking the plus sign (+) next to the Web server name will display a list of the available Web sites on this server, as shown in Figure 1.1. 4. Clicking the plus sign (+) next to Default Web Site will display a list of the virtual directories for this Web site, as shown in Figure 1.2. Virtual directories are simply logical directories that can contain physical directories.

Getting Started with ASP.NET

FIGURE 1.1 A list of virtual directories is displayed below Default Web Site.

5. Right-click Default Web Site and then select New, Virtual Directory (a virtual directory is a link to another physical directory that resides outside of the Web site tree).
FIGURE 1.2 Creating a virtual directory for the default Web site.

6. Figure 1.3 shows the screen that appears. From this screen, enter the alias that you wish to use to gain access to this directory (for example, ASP_Net_Examples) and then click Next.
FIGURE 1.3 The Virtual Directory Alias screen.

7. In the next screen, shown in Figure 1.4, browse to the location where you want your virtual directory to be and click Next. If no directory has been created for your ASP.NET pages, create one now, calling it C:\Inetpub\wwwroot\ ASP_Net_Examples, for example.
FIGURE 1.4 The Web Site Content Directory screen.

8. In the next screen, shown in Figure 1.5, select the appropriate access permissions for this directory and click Next. The default access permissions are Read and Run Script. These permissions are acceptable for all ASP.NET applications that will be hosted on this server.
FIGURE 1.5 The Access Permissions screen.

9. In the final screen, shown in Figure 1.6, click the Finish button, and the virtual directory will be completed.
FIGURE 1.6 Congratulations! You have finished creating a virtual directory.

Installing the .NET Framework SDK


In order to work with ASP.NET, you will first need to install the .NET Framework SDK on your Web server. To do this, you must first download the SDK from http://microsoft.com/net.

The new virtual directory will now appear as a node under the Default Web Site tree. Hour 2, Presenting Internet Information Services, will provide a more detailed overview of the features and benefits of Internet Information Services (IIS) on Windows 2000.

Hour 1

, TO DO

Make certain that your Web server has all the .NET Framework prerequisites installed. You must have Internet Explorer 5.5 as well as MDAC 2.6 installed prior to installing the .NET SDK. Follow these instructions to install the .NET Framework SDK on your Web server: 1. To install Internet Explorer, go to http://www.microsoft.com/windows/ie/ download/ie55sp1.htm and run the IE setup program. 2. Once the setup program is loaded and you have accepted the terms of the license agreement, Internet Explorer 5.5 will be installed on the computer. Reboot when the installation wizard prompts you. 3. Download MDAC 2.6 from http://www.microsoft.com/data/ download_260SDK.htm and install it on your Web server. MDAC 2.6 is necessary on the Web server for retrieving data from a database system such as SQL Server 2000. Follow the installation instructions on the page and continue to the next step when the MDAC installation is completed. 4. You can download a copy of the .NET Framework SDK if you dont already have a copy. Be warned though: The .NET SDK is a 111MB download. You can either download it in one huge file or break it up into 11 smaller downloads, depending on your bandwidth. The URL to retrieve the .NET Framework SDK is http://msdn.microsoft.com/downloads/net. 5. Once youve expanded the .NET Framework SDK download, double-click the setup.exe icon to begin installing the .NET Framework SDK. 6. A message will appear asking whether you want to install the .NET Framework SDK. When you click Yes, the installation program will extract all the .NET installation files necessary to complete the setup process. The .NET Framework SDK extraction process will take a few minutes to complete. 7. Scroll through the screens, pausing to accept the terms and conditions in the licensing agreement, until you reach the Install Options screen presented in Figure 1.7. Make sure the Software Development Kit box is checked; then click the Next button.

FIGURE 1.7 The .NET Framework SDK Install Options screen.

8. Choose the destination folder for the .NET Framework SDK and click the Next button. By default, the SDK installs to the directory C:\Program Files\ Microsoft.Net\FramewordSDK\. 9. The installation routine will begin installing the .NET components onto the Web server at this time (see Figure 1.8). Wait for the installation to complete and then reboot, when prompted, for the changes to take effect.
FIGURE 1.8 The .NET Framework SDK installing on the server.

Getting Started with ASP.NET

Once the .NET Framework SDK has been installed, you can begin developing ASP.NET applications. In the next hour, you will learn how to create your first ASP.NET page, along with which tools work best in the creation of these types of applications.

Summary
In this hours lesson, you were introduced to ASP.NETpart of Microsofts new .NET Framework strategy for distributed application development. You were also introduced to Internet Information Services on Windows 2000. Finally, you were shown the requirements necessary to host ASP.NET pages and how to install the .NET Framework SDK on your Web server.

Q&A
Q Where can I get more information on the .NET Framework SDK? A The first source of information is the .NET Framework Reference Guide thats installed with the SDK. To access it, click the Start button and then click Programs, Microsoft .NET Framework SDK, Reference Guide. You can also access information from Microsofts Web site at http://msdn.microsoft.com/net or http://www.microsoft.com/net. A third source of information is from newsgroups. Microsoft has set up several newsgroups for discussions of the .NET Framework SDK. The following newsgroups will be of interest to ASP.NET developers: microsoft.public.dotnet.framework.aspnet, microsoft.public.dotnet. framework.aspnet.mobile, and microsoft.public.dotnet.framework.aspnet. webservices. Finally, there are numerous sites devoted to ASP and ASP.NET programming. Some of the ones to visit include www.asp.net, www.gotdotnet.com, www.aspfree.com, and www.asptoday.com. Q Will I be able to run my existing ASP pages along with ASP.NET pages on the same server? A Absolutely! ASP.NET has been designed to coexist in complete harmony with ASP pages on the same server. In fact, you can have half of your Web site done in regular ASP and the other half in ASP.NET. This certainly helps the application migration path from ASP to ASP.NET.

Hour 1

Workshop
The quiz questions and exercises are provided for your further understanding of the material presented. See Appendix A, Answers, for answers to the questions.

Quiz
1. On which operating systems can you install the .NET Framework SDK? 2. What operating systems can host ASP.NET pages? 3. Do ASP.NET pages use interpreted code, where an interpreter reads each line of code in the page for processing, or compiled code, where the page code is compiled into executable code for the Web server?

Exercises
1. Explore the files in the directory of your default Web site. Notice the creation of a new folder called aspx. This folder holds the latest version of the ASP.NET validation code for ASP.NET pages. Do not modify anything in this page without first making a backup copy. Continue navigating your Web server using the Internet Services Manager Console.

Answers for Chapter 1 Quiz


1. On which operating systems can you install the .NET Framework SDK? Windows 2000, Windows NT 4.0 with Service Pack 6a, Windows 98, Windows Me. 2. What operating systems can host ASP.NET pages? Windows 2000 and Windows NT 4.0 3. Do ASP.NET pages use interpreted code, where an interpreter reads each line of code in the page for processing, or compiled code, where the page code is compiled into executable code for the Web server? All ASP.Net pages are compiled into executable code.

Anda mungkin juga menyukai