asp.net mvc 应用程序和 Linq2Sql 中的动态连接字符串用于多租户应用程序和表单身份验证

发布于 2024-10-26 17:38:35 字数 338 浏览 8 评论 0原文

所以我正在使用 asp.net mvc SQL Server 2008 和 Linq2SQL 开发一个 SAAS 应用程序 我有一个主数据库,我将在其中存储有关客户端的信息,例如名称子域/主机名信息和其他内容,并且每个客户端使用一个数据库对于实际的客户端数据,

为每个单独的数据库生成和使用连接字符串的最佳方法是什么?连接字符串将基于每个客户域,因此我可以在客户创建时将其硬编码到主数据库中,并基于以下内容创建 DataContext那?这个策略有什么缺陷吗?

我还使用表单身份验证,它将内置到每个客户端自己的数据库中,所以我是否已动态添加任何内容到配置中?目前,身份验证/成员身份由 web.config 文件中的连接字符串驱动

so I'm developing a SAAS application using asp.net mvc SQL server 2008 and Linq2SQL I've a master db where I'll store information about clients like name subdomain/hostname information and other stuff and I'll use one database per client for the actual client data,

what is the best way to generate and use the connection string for each individual db the connection string will be based on each customer domain so I could hard code it into master db at customer creation and create the DataContext based on that? any flaws in this strategy?

I am also using forms authentication and it will be built into each clients own db so do I've add anything dynamically to the configuration? as currently the authentication/membership is driven by connection string inside the web.config file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾城如夢未必闌珊 2024-11-02 17:38:35

您可能应该在集中式主数据库中有一个表,其中包含每个客户端的数据库连接信息。然后,在 SAAS 应用程序中,每当实例化数据上下文时,不要使用默认的无参数构造函数,而是使用构造函数重载,该重载接受您存储在该客户端的集中式数据库中的连接字符串。上下文不应在请求之间保持活动状态,因此跨多个客户端的跨页面请求不应该出现问题。

You should probably have a table in a centralized master db that includes the database connection information for each client. Then in your SAAS application, any time you are instantiating the data context, instead of using the default parameterless constructor, use the constructor overload that takes the connection string you stored in the centralized database for that client. The context shouldn't be kept alive between requests, so you shouldn't have a problem with cross page requests across multiple clients.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文