替换 ASP.NET 网站上某些用户的 ConnectionString
我修改asp.net网站。我需要为用户使用不同的连接字符串。网站使用实体框架进行数据访问。
如何在运行时替换设置? 我可以使用指定的 ConnectionString 进行实例化,但它需要多次更改,因为到处都使用默认构造函数。
我找到了项目的解决方案 - 使用部分类进行设置。但网站中没有设置(也许我弄错了?)。
I modify asp.net Web Site. I need use different connection strings for users. Web Site use Entity Framework for data access.
How can I substitute settings in runtime?
I can instantiate with specified ConnectionString, but it will require multiple changes, because used default constructor everywhere.
I find solution for projects - using partial class for Settings. But Settings no in Web Site (I mistake maybe?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地从 web.config、数据库或任何使用它的地方加载新的连接字符串,并在创建它时将其分配给您的上下文对象。看:
http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/2efc32f7-23ad-4fad-84cf-279badb394a5
You can simply load a new connect string from either your web.config, database, or whereever you use it and assign it to your context object when you create it. See:
http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/2efc32f7-23ad-4fad-84cf-279badb394a5