Monthly Archives: June 2013

Examine User Identity and Claims from Visual Studio Debugger

When debugging a claims-aware application (you ARE using claims, aren’t you?), sometimes it is useful to answer the question “which user is logged in (if any) and (if so) which claims are associated with said user.”

Assuming you are using Visual Studio and .NET 4.5, the simple solution is to add the following to one of your Visual Studio Watch windows:

System.Threading.Thread.CurrentPrincipal

[If you happen to be debugging ASP.NET code, you could save a little typing and instead add User to your Watch window. User should have the same value as the CurrentPrincipal in the context of ASP.NET. For ASP.NET WebForms User is a property of the Page class (Page.User), while for ASP.NET MVC User is a property of both the Controller class (Controller.User) and the HttpContext class (HttpContext.User).]

Drill in, and you will see something like the following:

image

If you then right-click on the Results View entry under Claims (the one that says “Expanding the Results View will enumerate the IEnumerable”) and, uhh, click on that entry to expand the results view, you will see all the claims.

In my case, some claims were flowing through Windows Azure Access Control Service (ACS), and these list the ACS namespace as the Issuer. Other claims were added at runtime by my code using a ClaimsAuthenticationManager module, and these list LOCAL AUTHORITY as the Issuer.

image

Alternatively, you can add the more complex direct expression to your Watch window – using the cast to coerce the right values:

((System.Security.Claims.ClaimsPrincipal)(System.Threading.Thread.CurrentPrincipal))

This will also do the job – with a little less drilling.

Advertisement

Visual Studio Ultimate 2012’s “Generate Dependency Graph” helps quickly visualize system dependencies

Recently I was exercising some of the OData APIs for manipulating a Windows Azure Access Control Service (ACS) namespace. I found some nice sample code, but the sample code was super-extensive (even including a Windows Phone sample), but my needs were humble (I wanted to manipulate ACS Reply-To addresses). After cutting out a few of the obvious projects so I could find “the code that mattered” I was still left with a heap of projects and libraries to weed out to get to the essential code – and it was tedious and error-prone to manually do this (if I was too aggressive, I broke the solution so it would no longer build). Frustration! How could I efficiently zoom in on the code I cared about so I could ensure I understood its requirements and dependencies?

This was two easy steps:

1. Create a simple program to exercise the code I cared about. This was a Console app I called TestRealmLib.exe.

2. Figure out everything that TestRealmLib.exe really depended upon.

Step one was easy since I knew the functionality I wanted to exercise.

Step two was easy once it dawned on me to use the right tool for the job: Visual Studio Ultimate 2012’s Generate Dependency Graph tool found under the ARCHITECTURE menu option.

NOTE: My understanding is that this feature is only fully available with Visual Studio Ultimate 2012, partially available in Premium (view but not create), and not available in lower editions – compare what’s included in which Visual Studio editions here: http://www.microsoft.com/visualstudio/eng/products/compare. I only have personally used it with Visual Studio Ultimate 2012 on solutions with C# projects (though I understand C++ is also supported, and assume any .NET language would work as well).

Running this for the whole solution, and rearranging the nodes with my mouse, quickly let me see where all the dependencies were.

image

I was quickly able to see that the modules I dragged to the right-hand side of the graph were not necessary, and those few on the left were the key. That was the answer I needed, but there are other interesting features. For example…

The thicker dependency lines represent more dependencies than the thinner lines. To drill in, right-click on a dependency line. Here’s what you get when you choose Advanced > Show Contributing Links on New Code Map:

image

Also note the “red dot” in the Code Map – this is indicating that I currently have a breakpoint set in there – yes, this is debugger-aware.

There are a bunch of other nifty features with this that you can check out here. These include dependency analysis, “Show Contributing Links” (on the dependency VisualStudioDependecyGraphWithLegendlink to show which parts of module you are calling), and more. The UI gestures you’d expect all do something reasonable – like double-click, right-click, whether on nodes or lines. You can double-click a class or method name to jump to your C# code. And don’t forget to turn on the Legend (from toolbar at top of graph, not shown in my screen grabs) and explore the other features.

There is also a nice video demonstration in Channel 9: http://channel9.msdn.com/Series/Visual-Studio-2012-Premium-and-Ultimate-Overview/Visual-Studio-Ultimate-2012-Understand-your-code-dependencies-through-visualization

Talk: What’s New in Windows Azure – New England Microsoft Dev Group

A couple of nights ago, I had the privilege of speaking at the New England Microsoft Dev Group in Waltham, MA. The topic covered a general and high-level overview of the broad capabilities of the Windows Azure Cloud Platform, with some specific topics added by attendees as well. It turned out to be an interactive session with good questions from the group.

We agreed I would come back after the summer for an architecture-focused session; the session presented was more feature & technology-oriented.

A few followups:

The deck I used is pretty short, but here in case you are interested:

My book, if you are interested, is described here (note: my next talk to the group will cover material more closely associated with the book, which is more focused on patterns and architecture in the context of designing effective cloud applications).