开发者

How do I share usercontrols/functionality between sites?

开发者 https://www.devze.com 2022-12-31 08:07 出处:网络
We have two asp.net sites (based on episerver). Using Telerik Asp.net controls. We have some functionality that we want to have available in both sites.

We have two asp.net sites (based on episerver).

Using Telerik Asp.net controls.

We have some functionality that we want to have available in both sites.

Right now one of the sites use webparts/usercontrols and the other uses usercontrols.

Is there any way to share the functionality between开发者_如何学Python these sites?

What I would like is to be able to share usercontrols between the sites.


Since your talking about user controls I'm assuming you also have .ascx files that are part of the user controls, which makes this tricky.

I guess the ideal solution would be to move everything into server controls, that way you could just reference the assembly, but if you are inheriting from other controls that utilize .ascx files, your kinda stuck with them.

One way of handling it is to use the file linking capabilities in Visual Studio (Add Existing File, click the down arrow, choose link option) to share the same physical file between projects within the same solution. This is not ideal simply because you have to make sure that the ascx files are copied to both sites prior to deployment (I've done it with a post-build script before), but there is a lot that can still be pretty fragile.

Another option that is more technically complex, but probably a "better" way of handling it would be to use a Virtual Path Provider to do the work for you. Here is an article which talks about using Virtual Path Providers to do the sort of thing you are wanting to do.


Start a new class library project, reference that project in both your site projects, then pull out the common controls and code into the library project.


Like mentioned you could put the files in a VPP directory in the live environment and that way only have to copy ASCX-files to one folder for a two-site-code-infront-update. Code-behind updates would need the DLL built and overwritten for both sites though.

If you are using SVN in your development environment you could also setup a svn:external linked folder from one of the projects and that way only have the code and it's revision history in one repository.

0

精彩评论

暂无评论...
验证码 换一张
取 消