|Delphi Clinic||C++Builder Gate||Training & Consultancy||Delphi Notes Weblog||Dr.Bob's Webshop|
Debugging ASP.NET on Windows Vista and IIS7
Using Delphi for .NET and CodeGear RAD Studio
In this paper, I will discuss a problem introduced by Windows Vista and IIS7 related to the act of debugging ASP.NET applications using Delphi for .NET (i.e.Delphi 8 for .NET, Delphi 2005, Delphi 2006 or Turbo Delphi 2006 for .NET) as well as the way things work using CodeGear RAD Studio 2007.
Vista and IIS7?
As a Delphi developer, I've been writing and deploying web applications for ages. Mostly against Microsoft's Internet Information Server (IIS), although I've also used Apache on Windows as well as Linux. This article is about IIS only. Windows NT Server came with IIS version 4, but with Windows 2000 we got IIS 5. This is almost the same version that's available in Windows XP Professional - IIS 5.1. Note that Windows XP Home edition does not come with IIS (but I'm hoping most web developers are professional anyway, not using a Home edition of Windows).
Still, that's not the version of IIS which I use most often, or which I find on Windows-based web server hosts most often. I'm talking about IIS version 6 of course, which comes with Windows Server 2003. A couple of years ago I was working on an ASP.NET project using C#Builder (before Delphi 8 for .NET was even released), using Windows 2000 and IIS 5 as development machine. Everything worked fine, until we deployed the application and we got all kinds of database security permission errors from the actual web server, which was using IIS 6 running on Windows Server 2003. We managed to solve the problem (reproducing it was hard, until we realised it had to do with IIS 6 vs.IIS 5), and ever since that day, I'm running Windows 2003 on my quattro-boot machine (it used to be dual and then triple boot, but now I have Windows 2000, Windows XP, Windows 2003 and Windows Vista on my development machine - using only Windows 2003 when working on web applications for the aforementioned reason).
So far so good. Enter Windows Vista. Right when you feel you've got everything under control, Microsoft comes by and rewrites the rules. The Windows Vista GUI and UAC experience is one thing - I can handle that, and with a bit of work my VCL applications, can too. But the trouble began when some of my clients got themselves new laptops - equipped with Windows Vista nowadays - and used them to develop ASP.NET 1.1 applications using Delphi for .NET. Since Windows Vista was released after even Delphi 2006 shipped, it appears there was no real support for Windows Vista inside (check my Dr.Bob Examines #84 article to see what you have to do to even install Delphi and its updates on Windows Vista - including the online help).
It quickly became clear that Windows Vista uses version 7 of the Internet Information Server. And although there is an "IIS 6 configuration compatibility" option you can install, Delphi 2006 still has trouble recognising that a virtual directory (now called application) is configured using ASP.NET 1.1, and will refuse to launch the application from the IDE when using IIS as host. It works fine using Cassini, but that's as bad as using IIS 5 on Windows 2000, since it will not give you a good overview of what the final deployment version of IIS will treat the application like.
Speaking of final deployment version of IIS - it's nice that Windows Vista comes with IIS 7, but that isn't really a web server deployment operating system is it? In fact, we have to wait until Windows Server 2008 ships - sometime next year, you guessed it - which will contain IIS 7.1. Note the .1, which means it may not even be 100% the same as IIS 7 currently included with Windows Vista. To cut a long story short (too late): in my personal view, Windows Vista and IIS 7 is not an ideal combination to develop web server applications. But if you have no choice (for example if your new machine comes with Windows Vista pre-installed, and you do not or cannot install Windows Server 2003 on it), then read on for some steps that may help you in debugging ASP.NET applications on Windows Vista using Delphi for .NET.
Vista and Permissions
The first problem you may encounter on Windows Vista when trying to create a new ASP.NET web application is a security issue: the c:\Inetpub folder cannot be modified by normal Users. While it was almost common to run Windows as "administrator" in previous versions of Windows, this is considered a no-no under Windows Vista. However, as a regular user - even when a member of the Administrators group - you lack the permission to create new directories or files in certain places.
There are two ways to fix this, as well as an "I give up" workaround. The latter means you just create your ASP.NET web projects elsewhere on your disk, for example in the \Users\ subtree like the \Users\<username>\My Documents\RAD Studio directory where you have permission to create and store them. But that's just lame. A more dangerous solution is to give your account Write permission in the c:\Inetpub\wwwroot directory. This will work, but it also means that you can always change these directories from now on (and there was a good reason to secure them from everyday access).
The final solution that I'm now using on Windows Vista is to start the Delphi IDE with the "Run as Administrator" option. This will ensure that the IDE is able to create the ASP.NET application and settings needed.
IIS 7 and IIS 6 Compatibility
Before we should start the Delphi IDE in Administrator mode, we have to ensure that IIS 6 compatibility is enabled on Windows Vista. To do this, go to the Control Panel, Click on Programs, and then on "Turn Windows features on or off" (this will invoke the User Account Control dialog). In the Internet Information Services, Web Management Tools, IIS 6 Management Compatibility subtree, we have to check the "IIS Metabase and IIS 6 configuration compatibility" leaf node, as shown in the screenshot below:
This will install the IIS metabase and compatibility layer to allow metabase calls to interact with the new IIS 7.0 configuration store.
ASP.NET 1.1 on IIS 7
Then, we need to enable ASP.NET 1.1 on IIS 7 (which by default enables ASP.NET 2.0 but disables ASP.NET 1.1). In order to enable ASP.NET 1.1, we have to start the "Internet Information Services (IIS) Manager", which can be found in the Administrative Tools (or in the Computer Management Console).
Here we need to select the machine itself - VISTA (Vista\Bob) in my case - and in the Features View double-click on the "ISAPI and CGI Restrictions" (few people remember that ASP.NET is in fact realised in part by an ISAPI Filter).
The ISAPI and CGI Restrictions window will confirm that by default ASP.NET v1.1.4322 is Not Allowed on Windows Vista (even if it's installed), while ASP.NET v2.0.50727 is.
Obviously, we need to Allow ASP.NET v1.1.4322 here as well.
Delphi for .NET and ASP.NET 1.1
Now it's time to start Delphi 2006 (or 2005 or 8).I'll handle the new CodeGear RAD Studio in a minute. The important part is to start it with the "Run as administrator" option. If you don't run Delphi 2006 "as Administrator", you will not be able to write to the C:\inetpub\wwwroot directory, for example after we do a File | New - ASP.NET Web Application - Delphi for .NET action. The error message is a bit cryptic, although it contains the real reason (telling you that "Application name is invalid or the location specified is read only or not a valid path.").
Assuming we didn't get the error, we can create a simple ASP.NET application by placing a Button, Listbox and TextBox control on the WinForm, and writing one line of code in the Click event of the Button, as follows:
procedure TWebForm1.Button1_Click(sender: System.Object; e: System.EventArgs); begin ListBox1.Items.Add(TextBox1.Text); end;We can set a breakpoint on the line that adds the TextBox' Test to the Listbox, and press F9 to Run (or to Debug actually). Unfortunately, this will give you an error regarding the virtual directory. It appears that Delphi for .NET is able to create the virtual directory, but is unable to confirm that it was configured for ASP.NET 1.1 correctly.
ASP.NET 1.1 Application Pool
Although both ASP.NET 2.0 and ASP.NET 1.1 were installed on Windows Vista (ASP.NET 2.0 by default, and ASP.NET 1.1 as a result of installing Delphi for .NET - the version prior to CodeGear RAD Studio), the default configuration used for new virtual directories (or applications, as they are called) is ASP.NET 2.0, and not ASP.NET 1.1
We can verify this in the Internet Information Service Manager. In the IIS Manager, open up the Server node then the, Web Sites, Default Web Site, WebApplication42 (the new of my Delphi for .NET ASP.NET web application) and then click on Basic Settings. This will show that the DefaultAppPool is being used, as shown below:
Unfortunately, this DefaultAppPool is for ASP.NET 2.0. We need to click on Select and change this to use the ASP.NET 1.1 application pool instead. This will use the .NET Framework Version 1.1 classic pipeline mode.
Unfortunately, while this change will ensure that the ASP.NET web application is using the ASP.NET 1.1 application pool, we will still get the same error when trying to run or debug it from the Delphi for .NET IDE. Even when doing Run | Run without Debugging, to avoid having to start the debugger, we still get the same error. The details show that the problem is the fact that Delphi thinks this is not the correct version of ASP.NET.
If we can't start the process from the IDE, perhaps we can start the process and bring it to the IDE instead.
Run | Attach to Process
A workaround that enables us to debug the ASP.NET 1.1 web application indirectly from the Delphi for .NET IDE, starts by using a browser and manually entering the URL for the web application (in this case http://localhost/WebApplication42/WebForm1.aspx). This will start the ASP.NET 1.1 application, as can be seen below (while in the middle of entering the text "Attach to Process demo")
Now we can use the Delphi IDE to attach the debugger to the ASP.NET 1.1 process. This is actually the w3wp.exe process, which can be seen in the Run | Attach to Process dialog.
Note that the w3wp.exe will only show up if we ran the ASP.NET 1.1 web application in a browser window. Also note that if you forget to put the ASP.NET web application in the ASP.NET 1.1 application pool, then it will be run as ASP.NET 2.0 application, running a w3wp.exe for ASP.NET 2.0, which cannot be used to attach the Delphi debugger to. You will get an "cannot create process" error if you try to do so (so every step we took was necessary to get this far).
Now the IDE will pause, and then you can run the application. Clicking on the button will finally trigger the breakpoint. Note the tooltip which shows the value of the EditText1.text property, which is "Attach to Process demo".
While this was not easy, for any future ASP.NET 1.1 web applications, we only need to mark the application as being part of the ASP.NET 1.1 Application Pool, and need to run the IDE "as Administrator". Then, we can use the Attach to Process to debug the application.
Closing the browser will not stop the debugging process, by the way, since we didn't start it. We have to manually do Run | Detach from Program afterwards.
CodeGear RAD Studio 2007
CodeGear RAD Studio 2007 is equipped with a better recognition of Windows Vista and IIS 7. In order to debug ASP.NET 2.0 web applications using CodeGear RAD Studio 2007 on Windows Vista we only need to install the "IIS Metabase and II6 configuration compatibility" and ensure that we run the IDE "as Administrator" (so the virtual directory can be created and configured). Other than that, it works fine.This is also explained in the ASP.NET Notes of the RAD Studio readme.htm file. The readme.htm also explains the step to take if IIS is running on a 64-bit operating system (since the assemblies that CodeGear RAD Studio produces are still only 32-bit). Finally, the readme.htm mentions that to debug an ASP.NET application using IIS 7 in Windows Vista, we must add the following directives to the project's web.config file (just before the closing </configuration> node):
<system.webServer> <modules> <add name="DbgConnect" type="Borland.DbkAsp.DbkConnModule,Borland.dbkasp,Version=10.5.0.0, Culture=neutral, PublicKeyToken=b0524c541232aae7" preCondition="managedHandler" /> </modules> <validation validateIntegratedModeConfiguration="false" /> </system.webServer>Without this addition, you will get the infamous "unable to attach to ASP.NET worker process (typically aspnet_wp.exe or w3wp.exe):
I only wonder why the <system.webserver> section wasn't added to the web.config in the first place - perhaps in comments, like the DbgConnect section is added to Delphi 2006 web.config files. But that's a question for another day.
Summary and Quality Central
In my personal view, Windows Vista and IIS 7 is still not an ideal combination to develop web server applications. But if you have no choice, then in this article I've explained the steps to allow Delphi for .NET 1.1 developers to (indirectly) debug ASP.NET 1.1 web applications running in Windows Vista and IIS 7, and also mentioned that it's a bit easier using CodeGear RAD Studio 2007 with an ASP.NET 2.0 web application. Running the IDE "as Administrator" is still required if only to configure the ASP.NET application directories correctly.
The described inability to debug ASP.NET 1.1 web applications on Windows Vista and IIS 7 from the Delphi for .NET directly, has been reported to CodeGear in Quality Central: report 50800). The report says it's "closed" right now ("need more info" - which I will supply). Please vote if you also want CodeGear to solve this issue as a patch for Delphi 2006 (thanks in advance!)...