Using Visual Web Developers Built-in Web Server
As you already know, Visual Web Developer has an integrated web server, which
makes it easy to develop ASP.NET web sites even on machines whose operating
systems dont have IISWindows XP Home Edition, for example.
To test the web server, well use a simplified version of the Hello.aspx file we
first saw back in Chapter 2, only this time well name it Default.aspx.
Visual Basic File: Default.aspx
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Hello, World!</title>
<script runat="server">
Sub Page_Load()
messageLabel.Text = "Hello, World!"
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="messageLabel" runat="server" />
</form>
</body>
</html>
C# File: Default.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Hello, World!</title>
<script runat="server">
void Page_Load()
{
messageLabel.Text = "Hello, World!";
}
</script>
</head>
<body>
<form runat="server">
157
Using Visual Web Developers Built-in Web Server
<asp:Label id="messageLabel" runat="server" />
</form>
</body>
</html>
You can start the web server by executing the project: select Debug > Start Without
Debugging, or use the keyboard shortcut Ctrl-F5. Visual Web Developer will
load Hello.aspx in your systems default web browser, as shown in Figure 5.15.
Figure 5.15. Executing a page using Visual Web Developer
We executed this project without debugging it, but generally youll want to run
projects with debugging enabled (using F5, or Debug > Start Debugging). The
debugging features enable you to find and fix errors in your code; well learn more
about them towards the end of this chapter.
To enable debugging, you must modify an option in a file called Web.config,
which is your web applications configuration file. Well take a more in-depth
look at Web.config shortly. For now, all you need to know is that the first time
you try to debug the project, Visual Web Developer will ask you whether you
want to enable debugging in Web.config using a dialog like the one in Figure 5.16.
Click OK to confirm the action.
Once you click OK, the application will execute. The resulting browser window
should be the same as the one we saw in Figure 5.15, but this time you have more
control over your application, as well soon see.
You can tell that your application doesnt run through your local IIS if you look
at the URL loaded in the browser window. When you execute a project using the
integrated web server, it will run on a random port, and the complete URL location
will reflect the physical path. In Figure 5.15, you can see that the integrated web
server was running on port 1855, which explains the complete URL: http://loc-
158
Chapter 5: Building Web Applications
Figure 5.16. Enabling Debug Mode in Visual Web Developer
alhost:1855/Dorknozzle/Default.aspx. IIS usually runs on the default port,
which explains why it doesnt need to be mentioned explicitly.
Visual Web Developers web server displays one small icon in the system tray
for each web server instance thats running. If you run multiple projects at the
same time, more web servers will be created and more icons will appear. If you
double-click on one of those icons, youll be presented with a dialog that contains
the web server details, and looks very much like the window shown in Figure 5.17.
Figure 5.17. Visual Web Developers web server in action
As it executes the project, Visual Web Developer will launch your systems default
web browser, but you can make it use another browser if you wish. For the purpose
of running and debugging your ASP.NET web applications, you might find it
easier to use Internet Explorer as your default browser, as it works a little better
with Visual Web Developer than do other browsers. For example, if you close
the Internet Explorer window while your project runs in debug mode, Visual Web
159
Using Visual Web Developers Built-in Web Server

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.