多个网站之间如何共享资源?
我有三个不同的网站,它们使用一些基类、用户控件。我的问题是,是否可以从单个物理位置在这些站点之间共享这些资源?并且还想对所有三个站点使用单个 web.config。因为这将使我在维护问题上更加轻松。
那么,如果上述场景是可能的,那么如何实现它呢?
I have three different websites that uses some base classes, usercontrols. And my questions here is that it possible to share these resources between this sites from single physical location? And also want to use single web.config for all three sites. As this will give me much more ease on maintenance issues.
So, if the above scenario is possible than how to achieve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过创建项目的 DLL 并将该 DLL 放入 GAC 中来共享网站之间的资源。
全局程序集缓存或 GAC 是 Microsoft CLR 平台的计算机范围的 .NET 程序集缓存。拥有专门控制的中央存储库的方法解决了共享库概念,并有助于避免其他解决方案导致 DLL 地狱等缺陷的陷阱。
WIKI 上有关 GAC 的详细信息
配置数据,
根据概念 Web。如果您想共享配置数据而不是使用机器,则配置文件对于每个网站都是私有的。配置文件具有机器上运行的所有网站的通用数据
You can share the resouce between the website by Creating DLL of your project and put that DLL in GAC
The Global Assembly Cache or GAC is a machine-wide .NET assemblies cache for Microsoft's CLR platform. The approach of having a specially controlled central repository addresses the shared library concept and helps to avoid pitfalls of other solutions that lead to drawbacks like DLL hell.
Deatils about GAC on WIKI
For Configuration Data
as per the concepts Web.Config file is private for each web site if you want to share the configuration data than make use of machine.Config file which is having data common for all website running on the machine
您可以使用探测路径配置设置为每个应用程序定义一个可以找到共享程序集的位置。这意味着您不需要对程序集和程序集进行强命名。将它们存储在 GAC 中(尽管这可能是最好的方法)
如果您想在应用程序之间共享配置,您可能需要创建一些备用配置系统。正如 @pranay 所说,web.config 是应用程序私有的。如果这 3 个应用程序位于同一服务器上并且共享一个公共根(例如/apps/app1、/apps/app2、/apps/app3),您可以将配置放在父配置中。
You could use the probing path config setting to define a location for each app where they can find the shared assemblies. That would mean you wouldn't need to strongly name the assemblies & store them in the GAC (although that is probably the best approach)
If you want to share config across the apps, you'll probably need to create some alternate config system. as @pranay said a web.config is private to the app. if the 3 apps are on the same server & share a common root (eg /apps/app1, /apps/app2, /apps/app3) you can put the config in the parent config.