Section 4.1. Develop Web Apps Without IIS


4.1. Develop Web Apps Without IIS

With Visual Studio 2005 you no longer need to install and use IIS to host your web applications while you develop them. Now Visual Studio gives you four choices:


File System Web Site

This is the simplest alternative; just put all your files in a filesystem folder on your hard drive.


Local IIS Web Site

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.


Note: Visual Studio 2005 gives you four ways to manage web applications.

Remote Web Site

You can use Visual Studio 2005 to create applications that reside on remote servers as long as those servers support FrontPage 2000 Server Extensions.


FTP Web Site

Visual Studio 2005 allows you to create and maintain web sites on an FTP server.

4.1.1. How do I do that?

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.

Figure 4-1. Creating a new web site in Visual Studio 2005


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.

Figure 4-2. The New Web Site dialog


Click OK. You are placed into the Default.aspx file, in Source view. Select Design view instead.


Tip: 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.

In the Button1_Click event 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.

Figure 4-3. The Debugging Not Enabled dialog


The default choice is to allow Visual Studio 2005 to create a Web.config file for you. Click OK.

4.1.2. What just happened?

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.

Figure 4-4. Visual Web Developer Web Server started



Tip: 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.

4.1.3. What about...

...editing the Web.config file that Visual Studio creates for me? Can I do that?

You can edit the file by hand, but it is much easier to edit it using the new Web Site Administration Tool (WAT).

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.

Figure 4-5. The Web Site Administration Tool page


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.

Figure 4-6. Configuring web settings



Tip: 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 at c:\[WindowsDirectory]\Microsoft.NET\Framework\[Version]\ ASP.NETWebAdminFiles.Look closely at the URL displayed when you choose Website ASP.NET Configuration. It will show you exactly which file it is displaying (e.g., [...]/appConfig/DebugandTrace.aspx).

...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.

4.1.4. Where can I learn more?

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.



Visual C# 2005(c) A Developer's Notebook
Visual C# 2005: A Developers Notebook
ISBN: 059600799X
EAN: 2147483647
Year: 2006
Pages: 95
Authors: Jesse Liberty

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