Friday, August 8, 2008

ASP.NET Development Tips/Tricks: Using "Attach to Process..."

I wanted to save this tip for later but I think it's too important to hold back. The one action of attaching to a process will save you minutes, that's right MINUTES, in your daily tasks.

You might have noticed in my last post about Keyboard Shortcuts I never mentioned the F5 key. That's because I never use it.

The F5 key is commonly used to "Start Debugging." Let's take a moment to walk thru what happens when you press F5. (Or click the green play button, or thru the menu Debug > Start Debugging)

2008-08-08_2244The F5 Way

  1. First, Visual Studio (VS) will build your startup project.
  2. Second, VS opens an instance of your configured browser and attaches to the browser's process.
  3. Third, VS will direct the browser to the start page of your start-up project.
  4. Forth, VS finally attaches to the process hosting ASP.NET
    1. w3wp.exe if you use IIS6
    2. aspnetwp.exe if you used IIS 5.5
    3. WebDev.WebServer.exe if you use the ASP.NET Development Server that comes with Visual Studio.

Now, lets assume you want to debug some new administrative feature you've added to your web application. After all of the "F5" steps, most likely you:

  1. Fifth, start on your start page (I'll assume Default.aspx)
  2. Sixth, click on the Login link
  3. Seventh, login with Username and Password
  4. Eighth, browse to the Administration page with the feature you want to test

Now, lets assume you have a bug in your code.  Your next step might be:

  1. Ninth, close the browser
  2. Tenth, change the code to fix the bug
  3. Goto First

The "Attach to Process..." Wayatp 

So, how can "Attach to process... " save you minutes? By not repeating the Second, Third, Fifth, Sixth, Seventh, Eighth, and Ninth steps from above.

Here is the process I use:

Once per day:

  1. Open Browser
  2. Browse to development website
    1. If Root: (http://localhost)
    2. If Virtual Directory: (http://localhost/vDirectory)
  3. Click Login link
  4. Login with Username and Password
  5. Browse to the Administration page where the new feature will be

That's right, I usually only do these 5 steps once a day.

Now, I write my new administrative feature. Then, it comes time to test my changes.

<note>
This is where my first three common "walks" of my last post become important.
</note>

  1. First, build the current web project if needed.
    1. (Alt, B, U)
  2. Second, attach to process hosting ASP.NET.
    1. w3wp.exe (Alt, D, P, W 3, Enter)
    2. aspnetwp.exe (Alt, D, P, A S P, Enter)
    3. WebDev.WebServer.exe (Alt, D, P, W E B, Enter)
  3. Third, switch to the open browser
    1. (Alt+Tab)
  4. Fourth, refresh page as appropriate
    1. (F5 or Ctrl+F5 or Alt+D, Enter)

Lets assume there is a bug in my new code. (I know it's hard to believe, but just for giggles lets assume.)

  1. Fifth, detach from the process hosting ASP.NET
    1. (Alt, D, D, [sometimes Enter])
  2. Sixth, change the code to fix the bug
  3. Goto First

Conclusion

By using "Attach to Process..." we save ourselves repeatedly launching and closing the browser, the login process, and the preliminary navigational steps to get to the code we want to test. These actions which took minutes and were repeated with every "F5" now are only done once.

3 comments:

  1. Great tip, Justin! I only learned about Attach to Process two years ago. I can honestly say that in the two years since I've only used the F5 way a couple of times - and I think those were when I was working on a console app or a web form. For an ASP.NET developer, who always has his project open in a browser, it is much easier to use Attach to Process.

    ReplyDelete
  2. This information about asp.Net development tips with attachment is very nice and useful for users and developers. Thanks for sharing.

    ReplyDelete