Participating in the Page Rendering Pipeline in SharePoint 2010 Sandbox Solutions – SPUserCodeWebPart

If you have been reading this blog of late, you probably picked up on the fact that I am a bit disappointed by the limitations of sandboxed solutions. I recently updated my original post on the subject to include the following:

<This is mostly wrong>

Issue #4 – Almost No Server Side Rendering – Forget About Using ASP.NET

I thought I would try to work around my ribbon issue with a simple custom WebControl. Turns out that, since the sandbox assembly is installed in ProgramDataMicrosoftSharePointUCCache, the regular worker process (w3wp.exe) that renders pages can’t load the custom UI assembly because it has no knowledge of the UCCache location. The same applies to code behind assemblies for ASPX.

You can create WebParts (sorta/kinda) but they are also extremely crippled. See

</This is mostly wrong >

Well, I got to thinking… ‘I know that you can create sandbox solutions that include Web Parts, and SharePoint is loading them somehow. Maybe there is a way to get my controls onto the page!’

Turns out there is!!! I give you SPUserCodeWebPart. This little guy can load your assembly and its controls from the user code store.

Description="My WebPart" Title="Howdy y'all"
AssemblyFullName="MySandbox, Version=, Culture=neutral, PublicKeyToken=9120be3acbd2f74f"


Bear in mind that Web Parts are just user controls and you can use them even when the page is not a Web Part page. That means you can use them on regular ASPX pages and on master pages. This means that you can access controls and handle events on the page that contains this hook – as long as the controls are also contained in your Web Part. It seems that the way this works is that SharePoint generates a page within a page using the SPUserCodePage and SPUserCodeForm classes. The pattern I will be trying will be an ASPX page with a single SPUserCodeWebPart that wraps the control that implements the page logic. If I need to get at the outer shell I’ll emit JavaScript to do so.


Author: Doug Ware