ASP.NET UserControl class library

前端 未结 6 1122
情话喂你
情话喂你 2021-02-08 12:11

Is it possible to create class libraries that contain UserControls so I can reuse them? If so, how? Is the markup compiled with the .dll? Thanks for any help!

6条回答
  •  情书的邮戳
    2021-02-08 12:39

    You can serve User Controls from a dll. You will just need to create a custom VirtualPathProvider to load the controls. This is essentialy what SharePoint does.

    Here is an article from Microsoft that explains the process:

    http://support.microsoft.com/kb/910441

    You can also do a search for 'VirtualPathProvider'.

    This example loads the code from a database, but you can modify it to load the code from the assembly as an embedded resource. We are doing this at my company to share a Master page across many sites and appdomains.

    One caveat, however. This will not work in a Medium trust environment. So if you are planning on deploying this to a shared hosting environment, make sure to do a test on your host to see if it will work first.

提交回复
热议问题