C# Tips

C# Tip Article

IIS WebSite Debugging Tip

A small note for how to debug a website (ASP.NET) hosted in remote test server.

Here is one way of debugging a website hosted in IIS on test server (or staging server). Debugging in local developer machine is relatively easy but there are cases when we need to debug website application on remote server (test or production). Let's assume that (fortunately) we have Visual Studio installed on the remote server.

  1. Run Visual Studio as administrator
  2. File -> Open Web Site
  3. Specify the website directory
  4. Set debug to true in web.config
    <configuration>
    	<system.web>
    		<compilation debug="true" targetFramework="4.0" >
    	</system.web>
    </configuration>
    
  5. Set breakpoint in code
  6. Attach w3wp.exe process (Debug -> Attach to Process)
  7. Launch browser and visit the webpage in question.

Another alternative way of debugging is to debug with development web server instead of attaching IIS worker process. This method does not use IIS process and use a separate dev web server from VS. There are cases when you need to use this method.

  1. Run Visual Studio as administrator
  2. File -> Open Web Site
  3. Specify the website directory
  4. In Solution Explorer, Rightclick on Project and choose [Proprerties Window]. And set [Virtual Directory] to / (to make it root)
  5. In Solution Explorer, Rightclick on Project and choose [Property Page]. Goto [Build] and change [Before running startup page] to [No Build]. (because sometimes VS compiler or .NET in the remote server might be old/different)
  6. Set breakpoint in the code
  7. Start debugging by clicking F5. This will launch default Web Browser
  8. After finishing debugging, stop debugging. Sometimes you might need to manually stop development web server such as ASP.NET Development Server (and/or Kill WebDev.WebServer40.EXE) or IIS Express. If an error occurs due to ASP.NET web server cache, update source code slightly (ex: adding a space) might help