Introduction to ASP.NET


In 2001, Microsoft created a buzz in not only the web development world but in the Windows development world when it introduced the .NET initiative (covered with more detail in the next section). The initiative's aim was simple: develop a line of products, platforms, and services that are interoperable for the developer and easy to use and integrate to the ordinary user. Flanked by platforms such as the .NET Framework, products such as Visual Studio .NET, MSN, Office, and more, and web services built directly into MSN such as Passport, .NET has risen as an initiative worthy of its hype.

Make no mistake about itASP.NET isn't just a set of upgrades to traditional ASP. Built into the .NET Framework (covered next), ASP.NET represents Microsoft's next generation server-side technology and represents a complete reinvention for its predecessor. ASP.NET supports compiled code written in C++, C#, Visual Basic .NET, and Jscript .NET. Even better, ASP.NET allows separation of code from HTML formatting (called code behind). Because the language can be compiled, it can run faster than interpreted counterparts such as ASP and PHP.

.NET and the .NET Framework

For the past several years, Microsoft has run a series of commercials that show executives interacting with software that is perceived to make the user feel as if the software is revolutionizing the way they do business. At the end of the commercial, the tag line says: "That's business with .NET." Great! What's .NET? To many, these commercials are vague and lend themselves to many questions: What is .NET? What is business with .NET?

When .NET was introduced to the public, there was such an overwhelming bombardment of marketing information that it was difficult to figure out what .NET was and what kind of advantage it could provide for an organization. Fortunately, the dust has settled and a clear definition of what .NET truly is has emerged. .NET is Microsoft's new strategy for delivering software as a service. By reinventing the Application Service Provider (ASP) business model, Microsoft hopes to achieve independence from the long-standing "box ware" paradigm. Here are the key features that make up .NET:

  • .NET Platform: The .NET platform includes the .NET Framework and tools to build and operate the services, clients, and so on. ASP.NET, which is the focus of this section, is a component of the .NET Framework.

  • .NET Products: .NET productswhich include MSN, Office, SharePoint, and Visual Studio .NETprovide developers a rich environment for creating Web services that use programming environments such as C++, Visual Basic .NET, ASP.NET, C#, and so on.

  • .NET Services: An initiative formerly known as "Hailstorm," .NET Services are a set of user-centric XML web services currently being provided by a whole host of partners, developers, and organizations hoping to build vertical market applications for devices, applications, and the Internet. The collection of My Services currently extends to passport, messenger, contacts, e-mail, calendar, profile, lists, wallet, location, document stores, application settings, favorite websites, devices owned, and preferences for receiving alerts. Figure 22.10 shows the MSN Explorer and some of the .NET My Services incorporated in its framework.

    Figure 22.10. The MSN Explorer is one of the .NET products and includes ways of interacting with a myriad of web services.


As you can see, .NET is merely a strategy and not a tool or service. It's by no coincidence that Microsoft pulled the ending tag line from those commercials and replaced it with: "Solutions for the agile business."

The .NET Framework, which is a standalone, installable Windows application of sorts, is the environment for which .NET applications are built. The .NET Framework is specifically designed for Windows and web applications but supports development across a larger spectrum. The three main parts of the .NET Framework are listed here:

  • The Common Language Runtime (CLR)

  • The Framework Class Library

  • ASP.NET

Although the .NET Framework is just a small piece of the pie, it lays the foundation for .NET applications and web services. Remember, that the .NET Framework, although crucial in the .NET strategy, is only a small piece of the .NET platform, and the .NET platform is just one-third of the .NET initiative.

Installing the .NET Framework and ASP.NET

Unlike ASP, the .NET Framework, which includes ASP.NET, doesn't come pre-installed on most operating systems. In fact, Windows Server 2003 is the only operating system that comes with the latest release of the .NET Framework pre-installed. However, this doesn't mean that installing the .NET Framework will be a pain. On the contrary, in most cases, installing the .NET Framework is as simple as visiting the Microsoft Windows Update website.

If you don't have Windows Server 2003 (which most of us probably don't), you'll need to install the .NET Framework and ASP.NET manually. The best method of acquiring the .NET Framework is to download and install it directly from the web, or more specifically, the Microsoft Windows Update website. The reason for this is simple: Windows Update will not only alert you of the fact that you don't have the .NET Framework installed (assuming you don't), it will also allow you to download and install it. It's like a detection and installation utility, all in one. To use Windows Update to install the .NET Framework and ASP.NET, follow these steps:

1.

Open your browser and visit the Windows Update website located at http://www.windowsupdate.com.

2.

When the site opens, you'll have the opportunity to choose from an express installation or a custom installation. Choose the Custom Install option. Windows scans your computer. This is the detection utility I mentioned.

3.

When it's finished running through the detection utility, choose the Select Optional Software Updates link from the left navigation menu. If the .NET Framework Redistributable option appears in the list, you don't have the .NET Framework and ASP.NET installed. Select the check box next to the option now. If this option is not in the list, you do have .NET Framework and ASP.NET installed and you're ready to begin working with ASP.NET.

4.

Assuming that you don't have it installed, click the Go to Install Updates link, located near the top right of the options list.

5.

Click the Install button. The Installing Updates dialog appears and begins installing the .NET Framework. When finished, the .NET Framework Redistributable is installed along with ASP.NET. You may or may not have to reboot your computer.

That's it! You're now ready to begin working with ASP.NET.

TIP

If you ever want to play around with the various tools included with the .NET Framework SDK, you can download that version from the asp.net website at http://www.asp.net/download-1.1.aspx. The .NET Framework SDK contains debuggers, compilers, MSDE, samples, and more. Be aware however, that file is 108 MB, so be prepared to wait while it downloads.


Creating a Simple ASP.NET Page

Now that you've had a formal introduction to the .NET Framework and ASP.NET and you've had a chance to install ASP.NET, let's walk through the process of creating a simple ASP.NET page. Not only will this process help familiarize you with the technology, you'll also get a basic understanding of how IIS and the .NET Framework handle the processing of a dynamic ASP.NET page. To create a simple ASP.NET page, follow these steps:

1.

Create a new folder in C:\Inetpub\wwwroot called DorknozzleASPX.

2.

Open Notepad (we'll get to Dreamweaver in a few sections).

3.

In the document, add the following code:

 <html> <head> <title>Sample ASP.NET Page</title> <script runat="server"> Sub Page_Load()      theTime.Text = Now() End Sub </script> </head> <body> <h1>The Date and Time is: <asp:label  runat="server" /></h1> </body> </html> 

4.

Save your work as sample.aspx in the new folder named C:\Inetpub\wwwroot\DorknozzleASPX.

TIP

If you plan on trying out numerous server-side technologies, it's beneficial to create the folder with the Dorknozzle name followed by the three-or four-letter server-side technology you plan to use. This convention prevents you from continuously having to redefine the site for every server-side technology.


To test your work, open the browser and type the URL http://localhost/DorknozzleASPX/sample.aspx. As you can see from Figure 22.11, the text "The Date and Time is:" along with today's actual date and time appear on the page.

Figure 22.11. Basic text and today's date and time appear on the page.


As you did with the ASP example, you've just created your first dynamic ASP.NET web page. I know, I know, it's getting less dramatic as we progress! Again, look at the code and see whether you can pick apart the dynamic portions of the page. In this example, the difference is much more dramatic than was the case with ASP. This is because ASP.NET is control based and event driven. ASP.NET makes use of dozens of controls beginning with the asp prefix, followed by a semicolon, and followed by the tag name. In our example, the Label control is used as a way to display today's date and time:

 <asp:label  runat="server" /> 

The Label control, as is the case with every other ASP.NET control, has two distinct attributes: the ID and the Runat server attributes. The ID is a way to uniquely identify the control on the page; the runat="server" attribute and value tells the browser and ultimately the web server that the .NET Framework should process this portion of the page.

Near the top of the page, I've outlined a code declaration block containing one event handler: Page_Load:

 <script runat="server"> Sub Page_Load() End Sub </script> 

It's called an event handler because it handles the page's load event and responds with code accordingly. In our case, we identify the Label control by name and set its built-in Text property to today's date using the built-in Now() function:

 theTime.Text = Now() 

The result, as you've seen, is text that is parsed by the browser and today's date which is fed to the browser by the .NET Framework. Unlike ASP, where the process was relatively straightforward, the process is slightly more complex in ASP.NET. In ASP.NET, the page is still fed through IIS. IIS, recognizing that a code with runat="server" attributes exists, intercepts the request and calls for help from the .NET Framework (running as a process called aspnet_wp.exe in the background). To see this process, simply press Ctrl+Alt+Delete, click the Task Manager option, and choose the Processes tab from the Windows Task Manager dialog. As you'll see, the aspnet_wp.exe worker process runs silently in the background.

The .NET Framework processes the request and takes the code to mean, "Print out the date and time within the page." The .NET Framework converts the Label control to a <span> tag (legitimate HTML) and responds back to IIS with plain old text and HTML tags. IIS then feeds that response back to the client browser, where we see the result in a clean and legible format. If you don't believe me that the .NET Framework always converts code to HTML, try viewing the source of the page in the browser by choosing View, Source (in IE). As you can see from Figure 22.12, the code declaration block (<script> tag) is removed from the page, the Label control is converted to a <span> tag, and the date and time is rendered as literal text.

Figure 22.12. The code declaration block (<script> tag) is removed from the page, the Label control is converted to a <span> tag, and the date and time is rendered as literal text.


That's ASP.NET in a basic nutshell. In this example, we manually coded the ASP.NET code. Again, the beauty in using Dreamweaver is that you don't have to do your own coding. Dreamweaver writes all the necessary code for you. More on this later; for now, let's focus on getting our project configured so that we can use ASP.NET to create dynamic Dorknozzle pages.

Configuring Dorknozzle to Run under ASP.NET

Up to this point, we've been working primarily from C:\Dorknozzle\<chapterfolder>. From now on, we'll work from C:\Inetpub\wwwroot\DorknozzleASPX (assuming that you're using ASP.NET). Because this is the case, we need to reconfigure the site definition to point to the new folder we've created. Furthermore, we need to configure the Testing Server category in the Site Definition window to provide Dreamweaver with information specific to the technology you plan on using for the defined site. To configure Dorknozzle to run under ASP.NET, follow these steps:

1.

If you haven't downloaded the files for this chapter, do so now. Open the folder for Chapter 22, copy the contents out of folder, and paste them into the newly created DorknozzleASPX folder in C:\Inetpub\wwwroot. You will then have all the assets, images, library items, and an index.aspx page you need to get started. After you've copied the files over, you should have Assets, Images, and Library folders including a CSS file, index.aspx page, and the sample.aspx page you've been working with to this point.

2.

Open Dreamweaver if you haven't already done so and choose the Manage Sites option from the Site menu.

3.

Select the existing Dorknozzle site from the list and click Edit. The Site Definition for Dorknozzle dialog appears.

4.

In the Site Name text box, rename the site from Dorknozzle to DorknozzleASPX.

5.

Browse to the C:\Inetpub\wwwroot\DorknozzleASPX\ folder in the Local Root folder category. Leave everything else as is.

6.

Switch to the Testing Server category.

7.

Select the ASP.NET VB option from the Server Model category.

NOTE

You can choose the ASP.NET C# options if you prefer. Because we'll rarely modify the code, the coding option you select here makes little to no difference.

8.

Now choose the Local/Network option from the Access menu. New properties become available that allow you to configure the location of the remote folder as well as the URL prefix for the remote folder.

9.

Browse to the same C:\Inetpub\wwwroot\DorknozzleASPX\ path in the Remote Folder text box. In most cases, this value is pre-populated when you select the Local/Network option from the Access menu.

NOTE

When working with web applications, the ideal scenario is that you'll have a development machine, a production machine (server), and a testing server. Realistically, not everyone can afford another server just for testing purposes. Because most of us will rely on the development machine to function as a testing server as well, we'll leave the testing server path as is. If you do have a dedicated testing server, you'd probably still choose the Local/Network option from the Access tab; however, rather than finding the machine locally, you'd browse to it on the network.

TIP

As you've seen in the Access menu, other options are available for defining remote access to the testing server. Similar to the Remote Info category, when you select FTP and WebDAV, you're presented with options for configuring the Host, Host Directory, Login, and Password information. The RDS option is specific to ColdFusion. We'll get to that later in the chapter.

10.

Now enter the URL to our Dorknozzle site in the URL Prefix text box. This value should read http://localhost/dorknozzleaspx/. Remember that, localhost, like every other domain name (such as yahoo.com and google.com) is a URL accessible from a browser. Rather than accessing the site from a server miles away, the browser knows that localhost (and the IP address 127.0.0.1 associated with it) is the URL for the local instance of IIS (your computer). It doesn't have to look too far for your files.

11.

Click OK to close the Site Definition for DorknozzleASPX window.

12.

Click Done to close the Manage Sites dialog.

You're now ready to begin building dynamic Dorknozzle pages using Dreamweaver and ASP.NET!

Using ASP.NET in Dreamweaver

Depending on the server technology you decide to use, features exposed in Dreamweaver's interface will change. For the most part however, you can bank on the fact that the following features are always available when working with any server-side technology, including ASP.NET:

  • The Insert Bar: A visual representation of objects available in the Insert menu, the Application category in the Insert bar allows you to visually insert various types of dynamic objects onto your page.

  • The Insert menu: Use the Application Objects and ASP.NET Objects submenus in the Insert menu to insert both generic application objects as well as ASP.NET specific objects.

  • The Application Panel: Divided into four tabs (Databases, Bindings, Server Behaviors, and Components), the Application panel provides the means for connecting to and accessing database data, binding that data to elements on the page, accessing various application objects, and consuming web services. When working with dynamic pages in Dreamweaver, you should always have this panel open.

  • The Tag Chooser: If you want to make fine-tuned changes to your ASP code, you can always choose specific tags from the Tag Chooser. Available by choosing the Tag option from the Insert menu choosing an option from the Tag Chooser opens the Properties dialog for the particular tag, allowing you to further customize attributes of the tag.

  • The Reference Panel: If you ever need help regarding the various ASP.NET objects, application objects, or tags, you can reference them from using the Reference panel, available by choosing Window, Reference.

Earlier, I mentioned that most of the dynamic functionality built into Dreamweaver is the same regardless of the server-side technology you decide to use. This becomes obvious with the Application Objects submenu in the Insert menu and the Application category in the Insert bar. The objects listed in these menus expose generic functionality that remains consistent regardless of server-side technology. What changes is the option below the Application Objects option in the Insert menu. This option (which varies from ASP Object, ASP.NET Objects, ColdFusion Objects, and PHP Objects, depending on which server-side technology you decide to use), displays specific content accordingly.




Macromedia Dreamweaver 8 Unleashed
Macromedia Dreamweaver 8 Unleashed
ISBN: 0672327600
EAN: 2147483647
Year: 2005
Pages: 237
Authors: Zak Ruvalcaba

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