Chapter One
Getting Started with ASP.NET 3.5
Ever since the first release of the .NET Framework 1.0 in early 2002, Microsoft has put a lot of effort and development time into ASP.NET, the part of the .NET Framework that enables you to build rich web applications. This first release meant a radical change from the older Microsoft technology to build web sites called Active Server Pages (ASP), now often referred to as classic ASP. The introduction of ASP.NET 1.0 and the associated Visual Studio .NET 2002 gave developers the following benefits over classic ASP:
A clean separation between presentation and code. With classic ASP, your coding logic was often scattered throughout the HTML of the page, making it hard to make changes to the page later.
A development model that was much closer to the way desktop applications are programmed. This made it easier for the many Visual Basic desktop programmers to make the switch to web applications.
A feature-rich development tool (called Visual Studio .NET) that allowed developers to create and code their web applications visually.
A choice between a number of object-oriented programming languages, of which Visual Basic .NET and C# (pronounced as C-Sharp) are now the most popular.
Access to the entire .NET Framework, which for the first time meant that web developers had a unified and easy way to access many advanced features to work with databases, files, e-mail, networking tools, and much more.
Despite the many advantages of ASP.NET over the older model, using ASP.NET also meant an increase of complexity and the knowledge you needed to build applications with it, making it harder for many new programmers to get started with ASP.NET.
After the initial release in 2002, Microsoft released another version of the .NET Framework (called .NET 1.1) and the development IDE Visual Studio .NET in 2003. Many people saw this as a service pack for the initial release, although it also brought a lot of new enhancements in both the framework and the development tools.
In November 2005, Visual Studio 2005 and ASP.NET 2.0 were released. To the pleasant surprise of many developers around the world, Microsoft had again been able to drastically improve and expand the product, adding many features and tools that helped reduce the complexity that was introduced with ASP.NET 1.0. New wizards and smart controls made it possible to reduce the code required to build an application, decreasing the learning curve for new developers and increasing the productivity.
The current version, ASP.NET 3.5, builds on top of the successful ASP.NET 2.0 release, leaving many of the beloved features in place, while adding new features and tools in other areas.
Over the next 18 chapters, you learn how to build full-featured ASP.NET web sites using Visual Web Developer, Microsoft''s development tool for ASP.NET web applications. This book guides you through the process of creating a fully functional, database-driven web, starting with a bare bones web site in this chapter, all the way down to the deployment of it to a production environment in Chapter 18.
To start off, this chapter gives you a good look at:
Visual Web Developer 2008 Express Edition and Visual Studio 2008 and how to acquire and install them.
Creating your first web site with Visual Web Developer.
The way an ASP.NET page is processed and sent to the browser.
How you can use and customize the development environment.
The chapter closes with an overview of the sample web site that comes with this book, the Planet Wrox web site. In this chapter, you''ll see what the site has to offer and how to use it; the remainder of this book then shows you the inner workings of the site and how it''s built.
The sample site and all the examples in this book are built with Visual Web Developer (VWD), so it''s important that you have it installed on your development machine, and know how to access its most basic features. The next section shows you how to acquire and install VWD. Once you have it up and running, you''ll see how to create your first web site, followed by an extensive tour through the many features of VWD.
Microsoft Visual Web Developer
Although you could theoretically write ASP.NET web applications with Notepad or another text editor alone, you really want to install a copy of Microsoft Visual Web Developer. VWD is developed specifically for building ASP.NET web sites, and as such, hosts an enormous amount of tools that will help you in rapidly creating complex ASP.NET web applications.
Visual Web Developer comes in two flavors: as a standalone and free version called Microsoft Visual Web Developer 2008 Express Edition, and as part of the larger development suite called Visual Studio 2008, which is also available in different editions, each with its own price tag. Although the Express Edition of VWD is free, it contains all the features and tools you need to create complex and feature-rich web applications. All the examples you find in the book can be built with the free Express Edition so there''s no need to shell out big bucks for the commercial versions of Visual Studio 2008 to follow along with this book. Getting VWD is easy. You can download it from the Microsoft site as discussed next.
Getting Visual Web Developer
You can get the free version of VWD from the Microsoft site at www.microsoft.com/express/. On the Express home page, follow the Download Now link until you reach the page that offers the downloads for the Express products, including Visual Web Developer 2008 Express Edition. From this page, you can download Visual Web Developer 2008 Express Edition as a Web Install, where you download only the installer, while the remaining files are downloaded during the installation process. Make sure you choose Visual Web Developer from the page, and not one of the other free Express products. The page also allows you to download all Express products conveniently as an ISO image that you can burn onto a DVD.
Don''t be fooled by the file size of the Web Install download, which is little under 3MB. The file you downloaded is just the installer that downloads the required files over the Internet. The total download is around 1.3GB.
If you want to try out the full version of Visual Studio 2008, which also contains VWD, you can sign up for a free 90-day trial that you can get from the Microsoft site at http://msdn2.microsoft.com/ vstudio. You can choose to download an ISO image that you''ll need to burn on a DVD.
Installing Visual Web Developer Express Edition
Installing Visual Web Developer is a straightforward, although somewhat lengthy, process. Depending on your installation method, your computer and your Internet connection speed, installing VWD may take up to several hours.
Try It Out
Installing Visual Web Developer 2008 Express Edition
This Try it Out exercise guides you through installing VWD Express Edition on your computer. It assumes you''re using the web download option, although the process for installing the Express edition from a DVD is almost identical. The steps you need to perform to install the full versions of Visual Studio 2008 are similar as well, although the screens you''ll see will be somewhat different.
No matter which version of VWD you install, it''s important that you also install SQL Server 2005 Express Edition - a required component if you want to follow along with many of this book''s examples. When you install the full version of Visual Studio 2008, the option to install SQL Server is included on the list with features to install that you see during setup. If you install VWD Express Edition, you get the option to choose SQL Server on the Installer Options dialog box. If you don''t see SQL Server listed on these dialog boxes, you probably already have SQL Server 2005 Express Edition installed.
1. When you''re installing the web version, run the file you downloaded from the Microsoft web site. Otherwise, start the setup process from the Visual Studio or Visual Web Developer DVD.
2. Once the installer has started, click Next, read and accept the license terms, and click Next once more.
3. On the Installer Options page, make sure you select both the MSDN Express Library for Visual Studio 2008 and Microsoft SQL Server 2005 Express Edition. Although these two options add considerably to the size of the download, both of them are invaluable for building ASP.NET web applications. If you don''t see the SQL Server option, you already have it installed. The Microsoft Silverlight Runtime component is optional, although it''s probably a good idea to download it now because you''ll see more and more web sites using Silverlight in the near future. Click Next again.
4. On the Destination Folder page, you can leave the Install in folder field set to its default if you have enough space on your primary disk. Otherwise, click the Browse button and select a different location.
5. Click the Install button. If you''re using the web-based installer, the setup application will first download the files over the Internet to your computer. During the installation process, you''ll see a screen (similar to Figure 1-1) that shows you the progress of the download and installation of VWD.
6. Once the application is finished installing, you may get a dialog box asking to reboot your machine. Click Restart now. Once your machine has started again, VWD is ready for use.
How It Works
The straightforward installation process guided you through the setup of VWD Express Edition. In the Installer Options dialog box, you selected the MSDN Library - which contains the help files for VWD - and Microsoft SQL Server 2005 Express Edition, Microsoft''s free version of its database engine. SQL Server 2005 is discussed and used a lot in this book, starting with Chapter 11. Appendix B shows you how to configure security settings for the various versions of SQL Server 2005 using the free SQL Server Management Studio Express Edition.
Now that VWD is installed, it''s time to fire it up and start working with it. The next section shows you how to create your very first site in VWD. You see how to create a site, add content to a web page, and view that page in your browser.
Creating Your First ASP.NET 3.5 Web Site
You probably can''t wait to get started with your first ASP.NET web site, so instead of giving you a theoretical overview of web sites in VWD, the next Try It Out exercise dives right into the action and shows you how to build your first web project. Then, in the How It Works explanation and the section that follows, you get a good look of what goes on behind the scenes when you view an ASP.NET page in your browser.
Try It Out
Creating Your First ASP.NET Web Page
1. Start VWD from the Windows Start menu if you haven''t done so already. The first time you start VWD, there is a long delay before you can use VWD because it''s busy configuring itself. Subsequent starts of the application will go much faster.
2. If you''re using a commercial version of Visual Studio, you also get a dialog box that lets you choose between different collections of settings the first time you start Visual Studio. The choice you make on that dialog box influences the layout of windows, toolboxes, menus, and shortcuts. Choose Web Development Settings because those settings are designed specifically for ASP.NET developers. You can always choose a different profile later by resetting your settings, as explained later in this chapter.
3. Once VWD is fully configured, you see the main screen appear, as shown in Figure 1-2.
You get a full description of all the windows, toolbars, panels, and menus in the next section, so for now, just focus on creating a new web site. Click the File menu in the upper-left corner and choose New Web Site. If you''re using a commercial version of Visual Studio, you may have to open the submenu New first. (Make sure you don''t accidentally use the New Project menu, as that is used to create different types of .NET applications.) The New Web Site dialog box appears as shown in Figure 1-3.
4. In the Templates section of the dialog box, verify that ASP.NET Web Site is selected. Also verify that File System is the selected option in the Location drop-down list. If you want, you could change the location on disk where the web site is stored by clicking the Browse button and choosing a new location on your computer''s hard drive. For now, the default location - a folder under your Documents folder - is fine, so you can leave the location as is.
5. In the Language drop-down list, you can choose a programming language you will use mainly in your site. This book shows all examples in both Visual Basic and C# so you can choose a language to your liking.
6. Click OK. VWD creates a new web site for you that includes one standard ASP.NET page called Default.aspx, a web.config file, and an empty App_Data folder, as shown in Figure 1-4. It also opens the file Default.aspx so you can see the code for the page.
7. Between the opening and closing
tags in the page, type the highlighted text and code:
Hello World
Welcome to Beginning ASP.NET 3.5 on <%= DateTime.Now.ToString() %>
You''ll see code formatted like this a lot more in this book. When you are instructed to type in code formatted like this with mixed background colors, you only need to type in the highlighted code. The other code should already be present in the file.
When you see code like this in a discussion - for example, in a How it Works section - the highlighted code is the part you need to focus on, while the code with no background is less important.
Don''t worry about the code with the angle brackets (<>) in the welcome message; you''ll see how it works later in this book. Although this code may not look familiar to you now, you can probably guess what it does: it writes out today''s date and time.
8. From the Debug menu in VWD, choose Start Without Debugging (or press Ctrl+F5) to open the page in your default browser, as shown in Figure 1-5.
If you don''t see the date and time in the page, or if you get an error, look again at the code in the welcome message. It starts with an angle bracket (<) followed by a percentage symbol and an equals sign. It closes with a single percentage sign and another angle bracket (>). Also, make sure you typed in the code exactly as shown here, including capitalization. This is especially true when you are using C#, as that language is case sensitive.
If you get an Information bar warning about Intranet settings in Internet Explorer, click the bar and choose Enable Intranet Settings. If you want to learn more about the implications of these settings first, choose What are Intranet Settings from the popup menu.
9. Notice how a little icon with a screen tip appeared in the tray bar of Windows, visible in Figure 1-6. This icon belongs to the ASP.NET Development Server. This web server has been started by VWD automatically to serve the request for your page. You''ll learn more about how the web server is able to process your page later in this book.
That''s it. You just created your very first ASP.NET 3.5 web site with VWD.
(Continues...)
Excerpted from Beginning ASP.NET 3.5by Imar Spaanjaars Copyright © 2008 by Imar Spaanjaars. Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.