So you want the world to see your sites Usage data, except you have a problem, access to the reports is only provided to the administrators of a site.  Well you could give everyone administrator rights and you could gnaw off your own foot but neither is a good idea the administration one less so.

So I know I’ll do this in a web part and just call some impersonation stuff, you know that WindowsImpersonationContext object will do fine. So you build a part, do the “Mike Yarwood” and whoooah now no one ‘cept you, can see your site.

So this is the point you get stuck, and think “google”.  After some searching I found Patrick Tisseghem’s blog with a post on this very subject.

First he solves your “Bang” no one see this, which could come in handy for Admin only web parts

SPControl.GetContextSite(HttpContext.Current).CatchAccessDeniedException = false;

But then comes up with good a old .NET running under COM+ example.  His example shows a webs.count usage, but UsageData works in the same way.

Another helpful article I found later in trying to get this mare to work ( I just love mixing Sharepoint, Gac, Com+  IISReset is your friend!!!)  was found here.  This article fills in some blanks about auto configuring the COM+ Application settings, What it doesn’t do is set the correct user, Make sure you go and set this else it will not work, make sure the user has sharepoint admin access to ALL areas, cos this is a web part anyone can use remember.

When using GetUsageData, remember that this information is gathered once a day so plenty of Caching opportunities here, don’t keep doing cross process communication as this has to be a Server component not a library one.

One thing that does puzzle me, is why dont my components spin in the Component Services tool when called ?

So Why ain’t I spinning then ? (and yes timeout of 3 minutes is set)

And one more thing, try at your own risk.  Im not saying it doesn’t work, just that you should investigate whats happening before you do it.

tags: , , ,