如何在 ASP.NET 中的 Web 应用程序之间共享用户控件? [英] How do I share user controls between web applications in ASP.NET?

查看:28
本文介绍了如何在 ASP.NET 中的 Web 应用程序之间共享用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是我关于 在网络应用之间共享资源,因为我还没有找到好的解决方案.

我有一个 Web 应用程序,其中包含由其他三个 Web 应用程序共享的用户控件和资源.

<上一页>解决方案|+-CommonControlsWebApp|+- 资源||+- 图片||+- 脚本||+- 样式表|+- 用户控件|+-WebApp1|+-WebApp2|+-WebApp3

这是我目前所知道的:

  • 我无法将 CommonControlsWebApp 编译成单个 dll,因为我正在创建用户控件.这仅适用于自定义服务器控件,其中所有内容都在代码隐藏文件中.所以我需要一种在四个项目之间共享 ascx 文件的方法.
  • 将文件从 CommonControlsWebApp 复制到其他三个项目不会在解决方案资源管理器中更新它们的文件.当在 CommonControls 中添加或重命名文件时,我必须在所有三个 WebApps 中都添加扩展项".
  • 更改为网站模型可以解决此问题,但如果我这样做,我担心 WebApp1-3 的编译时间.
  • 添加为链接"不适用于目录.
  • 我可以使用 Subversion 在项目之间共享文件,但我相信如果我正在开发一个我必须通过其中一个测试的用户控件,这将需要我一直重新签入和签出文件网络应用程序.

ASP.NET 真的没有一个好的解决方案吗?你们是如何组织大型网络应用程序的?

非常感谢所有的答案.我现在将使用构建事件复制我的用户控件,然后看看我们是否有时间将它们重构为服务器控件.

解决方案

我们现在的公司这样做的方式是确保 CommonControlsWebApp是一个 WebApplication,而不是一个网站.然后,您为文件夹使用名称,以帮助将其识别为与单个 Web 应用程序不同的常见文件夹.(CommonUserControls 而不仅仅是 UserControls)

在您的其他 Web 应用程序中,您为 CommonUserControls 等创建一个虚拟目录,并向 CommonControlsWebApp.dll 添加一个基于文件的引用

这要求您使用 IIS 进行开发(而不是 casini),Visual Studio 不会相信控件确实存在,但它会在运行时工作,并且您可以构建得很好,只需要警告 blahblah.ascx 或blahblah.master 路径无效.

如果您确实使用通用母版页和 Visual Studio 2008,则需要 SP1 for 2008 并在各个 Web 项目的根目录中使用 __fallback.master 以进入设计模式.

但是,我在另一个线程上看到了这个,我将考虑做更多这样的事情:http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

This question is a follow up to my question about sharing resources between web applications, because I have not yet found a good solution.

I have a web application with user controls and resources that are shared by three other web applications.

Solution
|
+-CommonControlsWebApp
| +- resources
| |  +- images
| |  +- scripts
| |  +- stylesheets
| +- UserControls
| 
+-WebApp1
| 
+-WebApp2
| 
+-WebApp3

This is what I know this far:

  • I can not compile CommonControlsWebApp into a single dll since I am creating user controls. This is only possible with custom server controls, where everything is in the code-behind file. So I need a way to share the ascx files between the four projects.
  • Copying the files from CommonControlsWebApp into the three other projects does not update their files in the solution explorer. I would have to 'add exting items' all in all three WebApps when a file is added or renamed in CommonControls.
  • Changing to the Web Site model would remedy this, but I am worried about the compile time for WebApp1-3 if I do this.
  • 'Add as link' does not work for directories.
  • I could use Subversion to share the files between the projects, but i believe that this would require me to check the files in and out again all the time if I am developing a user control that I have to test through one of the WebApps.

Can it really be true that ASP.NET does not have a good solution for this? How are you guys organizing large web applications?

Edit: Thanks a lot for all the answers. I am going to copy my user controls with a build event for now, and then see if we have time to refactor them into server controls.

解决方案

The way we do it at my present company is to make sure CommonControlsWebApp is a WebApplication, not a web site. Then you use names for the folders that would help identify it as the common ones that are distinct from the individual web apps. (CommonUserControls instead of just UserControls)

In your other web apps, you create a virtual directory to the CommonUserControls, etc, and add a file based reference to the CommonControlsWebApp.dll

This requires you to use IIS for development (not casini), and Visual Studio won't believe that the controls really exist, but it will work at runtime, and you can build just fine with only warnings about blahblah.ascx or blahblah.master path invalid.

If you do use common master pages and Visual Studio 2008, you will need SP1 for 2008 and use a __fallback.master in the root of the individual web projects to go in to design mode.

However, I saw this on another thread, and I am going to look into doing more like this: http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

这篇关于如何在 ASP.NET 中的 Web 应用程序之间共享用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆