Subscribe

RSS Feed (xml)

Sharing User Controls Across Application Domains

By design, User Controls are inaccessible outside of the application domain in which
they reside.This is for security reasons. However, this can be a limitation if you want to
share User Controls across several applications on a server. A fairly straightforward
workaround exists, which involves setting up a virtual directory within each application
that needs to use the User Controls, and mapping that virtual directory to a single physical
directory containing the User Controls.This solution is better than simply copying
the User Controls from application to application, because that would quickly turn into
a maintenance nightmare.

These steps were developed by readers of AspAlliance.com, and were first published
in the article listed at the end of this section.
1. Create a Web application project to hold the User Controls, and place the shared
User Controls in this project.
2. Create a virtual directory in each application that needs to use these shared User
Controls.This is done in the IIS manager by right-clicking on the application and
choosing New,Virtual Directory. Browse to the folder created for the Web application
in Step 1, and name the directory the same as that folder.
3. Create a reference from each application that needs the shared controls to the
shared controls.This is done in Visual Studio .NET from within the Solution
Explorer by right-clicking and choosing Add Reference. Browse to the bin folder
of the project created in Step 1 and select the DLL from that folder. (It should
have the same name as the project by default.)
4. Drag-and-drop will not work for these shared User Controls in VS.NET. Instead,
you must manually type the <%@ Register %> directive and specify the Src of the
User Control, referring to the virtual directory you set up

No comments:

Archives

Variety in the Web World