This post goes to a friend that needed to host a webpart in a page located in the _layouts folder.

Application pages are generic pages that will not be customized, will be deployed only once per web server and will be used across multiple site collections (these pages reside in the layouts server folder).  Therefore if you need to create an application page, you either write inline code (only allowed in application pages, not in site pages) or write a code behind class. I really haven’t found a good requirement that justifies the need of a webpart inside an application page.

Why would you need a webpart inside an application page? to me, if you need a webpart, then you’re looking for a site page, not an application page, anyways if somebody knows a good requirement for this please let me know.

Back to the point, eventhough it is told that webparts cannot be added to application pages and that the only way to add the webpart is in the form of a web control; the truth is that you actually CAN add webparts to application pages, however you won’t be able to customize them using the browser and they can’t be inside a WebPartZone.

If you’re adding a webpartzone with a webpart to your application page you’ll get an error “Unknown server tag WebPartZone”.

Web parts inside an application page are called “static web parts”, and behave like normal controls; and web parts inside a webpartZone in site pages are called “Dynamic web parts” and can be added and dropped at runtime (Thanks to Serge Luca for these concepts).

To add the web part just add it directly in MarkUp by registering the tag:

<%@ Register TagPrefix="ABC" Namespace="Namespace" Assembly="Assembly" %>

and directly adding the web part,

<ABC:ClassName ID="ControlID" FrameType="None" runat="server" __WebPartId="YouWebPartGUID" WebPart="true" />

As an example the next is an application page that contains a Content Editor Web Part:

And this is how the page looks:

hey Chris! I’m still waiting for the good business requirement of this! :)