Assembly Resource Virtual Path Provider

AssemblyResourceVirtualPathProvider is a virtual path provider that serves files stored in assembly resources. This comes very handy when developing a reusable module that needs pages, user controls or handlers that you don't want your end users to copy to their web application content folder. Instead, all they have to do is reference your assembly and aspx, ascx, ashx files can be embedded in the resources of the assembly.

AssemblyResourceVirtualPathProvider is automatically registered using PreApplicationStartMethod when your web application references OpenWaves.Web assembly.

You can also manually ensure the provider is registered by using the code below.
using OpenWaves.Web;
...
AssemblyResourceVirtualPathProvider.EnsureRegistered();

For security reasons AssemblyResourceVirtualPathProvider only serves resources marked as public using PublicAssemblyResourcesAttribute.

1. Embed your aspx, ascx, or ashx file as a resource (change Build Action of the file to "Embedded resource").

2. Mark the file as a public resource using PublicAssemblyResourcesAttribute
using OpenWaves.Web;

[assembly: PublicAssemblyResources("Contoso.UserControls.Foo.ascx")]

3. Reference your file using "~/App_Resource/AssemblyName/ResourceName" urls.
In markup:
<%@ Register TagPrefix="b" TagName="Foo" Src="~/App_Resource/Contoso.UserControls/Contoso.UserControls.Foo.ascx" %>

<b:Foo runat="server"/>

When loading controls:
var foo = page.LoadControl("~/App_Resource/Contoso.UserControls/Contoso.UserControls.Foo.ascx");

Or as urls to pages/handlers:
<a href="/App_Resource/Contoso.Pages/Contoso.Pages.Bar.aspx">Click to open resource embedded page</a>

CreateUrl

Last edited May 15, 2013 at 5:44 AM by mgrzyb, version 5

Comments

No comments yet.