多个 ASP.NET Web 应用程序取决于一个公共基础应用程序 [英] Multiple ASP.NET web applications depending on a common base application

查看:38
本文介绍了多个 ASP.NET Web 应用程序取决于一个公共基础应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于不同的客户,我有多个 SQL Server 数据库(相同的架构).他们将共享一个通用的 ASP.NET Web 应用程序.如果其中一位客户想要一个网页的定制版本,我们将在他的目录(或项目)中创建一个新版本.

I have multiple SQL Server databases (same schema) for different customers. They will be sharing a common ASP.NET web application. If one of these customers wants a customized version of a web page, we will create a new one in his directory (or project).

示例:

/Main Application/WebPage.aspx
/Main Application/WebPage2.aspx

/Main Application/Customer 1/WebPage.aspx

/Main Application/Customer 2/WebPage.aspx

目前,我有以下项目结构

At the moment, I have the following project structure

Solution (Main application)

    ASP.NET Main Project
    Other projects (BLL, DAL, etc.)

Solution (Customer 1)
    ASP.NET Project
    Other projects (BLL, DAL, etc.)

Same thing for Customer 2

在每个客户解决方案中,我都添加了对主应用程序项目的引用,以解决依赖关系并使用未自定义的网页.

In each customer solution, I added a reference to the main application project to resolve the dependencies and also to use the web pages that are not customized.

每个 ASP.NET 项目代表一个不同的 IIS 虚拟目录,因此我们在此示例中有 3 个.(/Main,/Main/Customer1,/Main/Customer2).

Each ASP.NET project represents a different IIS virtual directory, so we have 3 for this example. (/Main, /Main/Customer1, /Main/Customer2).

我现在遇到的问题是当我尝试连接到正确的数据库时.每个解决方案中的每个 ASP.NET 项目都有一个带有客户数据库连接字符串的 web.config 文件.当我从基础 ASP.NET 项目(主应用程序)运行程序(比如 WebPage2.aspx)时,我无法获得此连接字符串,因此我不知道要连接到哪个数据库.

The problem I have now is when I try to connect to the right database. Each ASP.NET project inside of each solution have a web.config file with the customer's database connection string. When I run a program (let's say WebPage2.aspx) from the base ASP.NET project (Main Application), I cannot get this connection string so I don't know what database to connect to.

我已尝试将所有连接字符串放在主应用程序 web.config 中,但我找不到在项目启动时引用正确字符串的方法.似乎没有办法设置自定义属性,我可以在其中在解决方案级别指定当前解决方案的连接字符串名称(或键).

I have tried to put all my connection strings in the main application web.config, but I cannot find a way to reference the right one when the project starts. There doesn't seem to be a way to set a custom property where I can specify the current solution's connection string name (or key) at the solution level.

对此有什么想法或想法吗?我不介意改变我的项目结构,但重要的是每个客户都有自己的解决方案,这样我们才能保持干净和独立.

Any ideas or toughts on this? I don't mind changing my project structure, but it is important that every customer has it's own solution so we can keep this clean and separated.

推荐答案

如果我是你,我会考虑从你的主应用程序库创建一个 NuGet 包.(NuGet 包可以完全保密,因此您不必担心开源要求...)

I would, if I were you, consider creating a NuGet package from your main application base. (NuGet packages can be kept entirely private, so you don't have to worry about open source requirements...)

使用 NuGet 包,您可以复制 dll 程序集、aspx 文件、xml 配置以及每个客户需要的几乎任何其他内容,只需将该包安装到客户的解决方案中即可.您可以在 IIS 中为每个客户创建一个单独的虚拟目录(甚至网站),他们都将拥有运行所需的一切.

With a NuGet package, you can copy dll assemblies, aspx files, xml configuration and virtually anything else each customer needs to have, just by installing the package into the customer's solution. You can create a separate virtual directory (or even web site) in IIS for each customer, and they will all have everything they need to run.

除此之外,通过这种方式,您还获得了另一件非常重要的东西:可维护性.您可以继续在主要解决方案中开发新功能和错误修复,并且只要您想将某些内容推送到客户站点,只需将更新发布到 NuGet 包即可.然后,您可以将该软件包更新安装到一个或所有客户特定站点中,但不必同时进行.如果某个客户站点由于某种原因需要滞后,这并不能阻止其他客户访问新功能.

On top of that, you gain another very important thing by doing it this way: maintainability. You can keep working on new features and bug fixes in your main solution, and whenever you want to push something to the customer sites, you just publish an update to the NuGet package. Then you can install that package update into one or all of your customer specific sites, but you won't have to do it at the same time. If one customer site needs to lag behind for some reason, it doesn't stop the other customers from getting access to new features.

创建 NuGet 包很容易,与多个解决方案相比,它将带您进入可维护性天堂不同解决方案中的站点依赖于另一个解决方案的构建,您甚至无法同时检查所有代码是否存在编译错误...

Creating a NuGet package is easy, and it will take you to maintainability heaven compared to a solution where multiple sites in separate solutions depend on builds from yet another solution, where you can't even check all your code at the same time for compile errors...

这篇关于多个 ASP.NET Web 应用程序取决于一个公共基础应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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