Wednesday, March 28, 2012

sharing UserControls, hoping this will be another feature for next ASP.NET

Since UserControls are so convienient, where the HTML of which can be easily edited and produces a recompile like ASPX pages, it would be nice to create a more easily shared control

Maybe the HTML could be stored as a string resource? and that would give the ability to localize the general HTML for languages too...

I'm curious what the ASP.NET PM's and/or dev's have to say about this...It is possible to share UserControls across websites on the same server now. Here's how:

** the controls to be shared cannot use code-behind. Put any script within the ASPX page.
** the controls to be shared must use the same language as the sites that will use them. So, if you have both C# and VB sites, you'll need 2 versions of the control.
** put the controls to be shared in a directory somewhere on the hard drive. Make sure the directory isn't an application to IIS, and that it doesn't have a web.config.
** now, in IIS, for each site that will use the controls, create a virtual directory that points to the directory that contains the controls.
** one last step--use IIS to turn off the "application" that it will create for the virtual directory.

Now the apps can load controls from the virtual directory. You'll have to do it by "memory" because the virtual directory won't show up in VS.NET's project listing, but the controls will load ok.

I'm using this method on several production sites on our intranet and it seems to work without a hitch.

Watch for this in an article on my aspalliance site in the near future.
nice. i had theorized about that method, its cumbersome but hey, it works ;-)

0 comments:

Post a Comment