7.16 Enable Web Site Debugging


Problem

When attempting to debug a Web application with Visual Studio .NET, you receive an "unable to start debugging on the Web server" error.

Solution

Ensure that Internet Information Services (IIS) is installed correctly, that IIS was installed before the Microsoft .NET Framework, and that Integrated Windows authentication is enabled for the Web application directory.

Discussion

The "unable to start debugging" error signals that Visual Studio .NET was able to compile the Web application but can't execute it in debug mode. Unfortunately, this problem can arise for different reasons, including the following:

  • IIS, the Windows component that hosts Web applications, is not installed or is installed incorrectly.

  • The user running Visual Studio .NET is not a member of the Debugger Users group for the Web server.

  • The user running Visual Studio .NET doesn't have permissions to debug the ASP.NET process. For example, if the ASP.NET process is running under the local system account, the user must have Administrator privileges to debug it.

  • The Web server is running a version of Windows that doesn't support debugging, such as Microsoft Windows NT and Windows XP Home Edition. (Windows 2000, Windows XP Professional, Windows XP Server, and Windows Server 2003 all support debugging.)

  • The Web application doesn't have a Web.config file, or the Web.config file doesn't enable debugging.

  • You're running Visual Studio .NET, and you haven't enabled Integrated Windows authentication for the virtual directory.

The first step that you should take when diagnosing why you can't debug a Web application is to check that IIS is installed on the Web server. To do so, open http://localhost/localstart.asp in your browser. (localhost is an alias for the current computer.) If the test page doesn't appear, IIS is not installed or is not enabled. You can also attempt to start your Web application without debugging by selecting Debug Start Without Debugging from the Visual Studio .NET main menu. If this test is successful, IIS is correctly installed.

If you installed IIS after you installed Visual Studio .NET or the .NET Framework, you might need to "repair" the .NET Framework by using the original setup CD or DVD. To start this process, type the following command at the command line (or in the Run window), using the Visual Studio .NET DVD. (It's split into two lines below because of page constraints, but it should be entered on a single line.)

 <DVD Drive>:\wcu\dotNetFramework\dotnetfx.exe /t:c:\temp    /c:"msiexec.exe /fvecms c:\temp\netfx.msi" 

If you're using the CD version of Visual Studio .NET, use the following command line with the Windows Component Update disc:

 <CD Drive>:\dotNetFramework\dotnetfx.exe /t:c:\temp    /c:"msiexec.exe /fvecms c:\temp\netfx.msi" 

If IIS is properly installed, the next step is to validate your Web application's Web.config file. The Web.config file should follow the structure shown here:

 <configuration>    <system.web>       <  compilation defaultLanguage="c#"   debug="true"  >    <!-- Other settings omitted. -->    </system.web> </configuration> 

By default, Visual Studio .NET adds the compilation tag to the automatically generated Web.config file with the debug attribute set to true .

The next step is to verify the IIS configuration. Problems will occur if you fail to create the required virtual application directory or if you try to run a Web application after you've removed or modified the virtual directory. To correct these problems, modify the virtual directory settings in IIS Manager by selecting Control Panel Administrative Tools Internet Information Services from the Start menu. Verify that the virtual application directory exists and that it's configured as a Web application. (You can see virtual directory settings by right- clicking the directory and choosing Properties.) For example, in the screen shot shown in Figure 7.9, the virtual directory exists but is not configured as a Web application. To resolve this problem, you simply need to click the Create button in the Application Settings section.

click to expand
Figure 7.9: A virtual directory that is not a Web application.

One other IIS configuration problem that can occur in Visual Studio .NET is a failure to authenticate. Visual Studio .NET attempts to access the local Web server using Integrated Windows authentication, even if you have anonymous authentication enabled for the virtual directory. This means that your virtual directory must allow both anonymous and Integrated Windows authentication. To allow both authentication methods , follow these steps:

  1. In IIS Manager, right-click the virtual directory for your application and choose Properties. (Alternatively, you can configure authentication for all directories if you right-click the Web Sites folder and choose Properties.)

  2. Select the Directory Security tab.

  3. In the Anonymous access and authentication control section, click the Edit button.

  4. In the Authentication Methods dialog box, under Authenticated access, select Integrated Windows authentication, as shown in Figure 7.10.

  5. Click OK to apply your changes.

    click to expand
    Figure 7.10: Enabling Integrated Windows authentication for debugging.

    Note  

    Microsoft describes these steps and some other troubleshooting steps for remote servers in a white paper at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtbshttpservererrors.asp .




C# Programmer[ap]s Cookbook
C# Programmer[ap]s Cookbook
ISBN: 735619301
EAN: N/A
Year: 2006
Pages: 266

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