The ASP.NET team at Microsoft set an ambitious goal for ASP.NET 2.0: to make it possible for web-site developers to build ASP.NET applications with 75% less coding. Their success means you will write a lot less plumbing code when you build ASP.NET 2.0-based applications, so that instead you can focus on making your web applications accessible and secure for your customers and clients. Among the improvements you'll find in ASP.NET 2.0 are powerful new controls, including data access controls that free you from repetitive database programming, and security controls that enable you to better manage user accounts and passwords. Also available are new controls for managing access to site data and for offering a uniform user experience across your web site's pages.
All of these features are available to C# programmers in all editions of Visual Studio 2005, with the exception of Visual C# 2005 Express Edition. Best of all, you no longer need Internet Information Server (IIS) to develop an ASP.NET application, a feature we'll investigate in the first lab.
This is the simplest alternative; just put all your files in a filesystem folder on your hard drive.
This works just like it did with ASP.NET 1.x. You can use Visual Studio 2005 to create web applications that reside either on the local IIS root or in a virtual directory.
You can use Visual Studio 2005 to create applications that reside on remote servers as long as those servers support FrontPage 2000 Server Extensions.
Visual Studio 2005 allows you to create and maintain web sites on an FTP server.
The first option, a filesystem-based web site, not only is completely new with ASP.NET 2.0, but also is one of the easiest ways to create a web application. You're likely to use it often. Let's explore that option here. To get started, open Visual Studio 2005 and choose File → New → Web Site..., as shown in Figure 4-1.
This menu choice opens the New Web Site dialog shown in Figure 4-2. Select ASP.NET Web Site in the Templates pane of the dialog. In the Location box choose File System. In the Language box choose Visual C# (this is, after all, a book on C#). Then in the box to the right of the Location box, choose a folder to house your ASP.NET files.
Click OK. You are placed into the Default.aspx file, in Source view. Select Design view instead.
Note two changes from Visual Studio 2003. Now the default is to put you in Source view rather than Design view, and within Design view the default is a flow layout rather than a grid layout. Thus, if you want absolute positioning, you must switch to grid layout. For this book we will follow the tradition of most web programmers and use tables for laying out pages when specific placement is needed.
Drag a label control and a button control from the Toolbox onto the form and double-click the button to open the code-behind file for the page. Notice (as noted in Chapter 1) that Visual Studio 2005 web forms use partial classes by default, so all the supporting code is not made visible to you.
handler, enter this code:
Label1.Text = "Hello.";
Try to run the application in debug mode. Visual Studio 2005 will interrupt to point out that you need a Web.config file with debugging enabled, as shown in Figure 4-3.
The default choice is to allow Visual Studio 2005 to create a Web.config file for you. Click OK.
You'll notice that a lot of things happened at once. You'll see a notification in your taskbar that Visual Studio 2005 has started the Visual Web Developer Web Server, as shown in Figure 4-4.
Visual Studio 2005 starts an instance of Visual Web Developer Web Server to test your application. Unlike IIS, which includes a web server, FTP server, SMTP server, and other facilities, the Visual Web Developer Web Server is used only to test web applications during their development.
Clicking your web form button will cause a post back to the Visual Web Developer Web Server and an update of the button label, just as if this application were being served by IIS. A quick look at the Solution Explorer will also confirm that Visual Studio has added the Web.config file to your project files.
...editing the Web.config file that Visual Studio creates for me? Can I do that?
Access the WAT by opening a browser and navigating directly to your .axd file (for example, http://localhost/TestWebApplication/Webadmin.axd) or, more easily, from Visual Studio 2005. To open the WAT from within Visual Studio 2005 choose Website → ASP.NET Configuration. The WAT for your application will open in a browser with four tabs, as shown in Figure 4-5.
Click the Application tab for links to pages that will allow you to create Web.config settings painlessly and accurately, as shown in Figure 4-6.
The Web Site Administration Tool page shown in Figure 4-5 is actually an
ASP.NET application. You'll find the source code on your hard drive
[Version] \ ASP.NETWebAdminFiles.
...what about deploying a file-based system?
Just copy the contents of your folder to a virtual folder on the server, and you're all set.
The Web Site Administration Tool is reviewed in great detail in the MSDN Help files under the article "Web Site Administration Tool Overview." Also, if you do a Google search for "ASP.NET Web Site Administration Tool" you will get literally thousands of hits, many of which will lead to articles on how to get the most out of this useful utility.