多个配置文件提供商
我有多个配置文件提供程序和配置文件类型:
ProviderA
和 ProfileA
和ProviderB
和 ProfileB
它们都使用不同的数据库。我希望能够说:
ProfileB.Create(...)
,并且配置文件是在数据库 B 中创建的,而 ProfileA.Create(...)
创建的数据库 A 中的配置文件。
我该如何在 web.config 中配置它?
以下内容(当然)是无效的:
<profile inherits="ProfileA, Authenticatie" defaultProvider="ProfileProviderA" enabled="true" automaticSaveEnabled="true">
<providers>
<add name="ProfileProviderA" applicationName="websiteA" type="ProfileProviderA, Authenticatie" connectionStringName="connstringA" description=""/>
</providers>
</profile>
<profile inherits="ProfileB, Authenticatie" defaultProvider="ProfileProviderB" enabled="true" automaticSaveEnabled="true">
<providers>
<add name="ProfileProviderB" applicationName="websiteB" type="ProfileProviderB, Authenticatie" connectionStringName="connstringB" description=""/>
</providers>
</profile>
I have multiple profile providers and profile types:
ProviderA
with ProfileA
andProviderB
with ProfileB
They both use a different database. I want to be able to say:
ProfileB.Create(...)
, and the profile is created in database B, whilst ProfileA.Create(...)
creates the profile in database A.
How the hell do I configure this in my web.config?
The following is (of course) invalid:
<profile inherits="ProfileA, Authenticatie" defaultProvider="ProfileProviderA" enabled="true" automaticSaveEnabled="true">
<providers>
<add name="ProfileProviderA" applicationName="websiteA" type="ProfileProviderA, Authenticatie" connectionStringName="connstringA" description=""/>
</providers>
</profile>
<profile inherits="ProfileB, Authenticatie" defaultProvider="ProfileProviderB" enabled="true" automaticSaveEnabled="true">
<providers>
<add name="ProfileProviderB" applicationName="websiteB" type="ProfileProviderB, Authenticatie" connectionStringName="connstringB" description=""/>
</providers>
</profile>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经使用以下技巧通过多个配置文件和提供程序解决了这个问题:
首先:为您的配置文件创建一个基类。它不必包含所有字段;重要的是它们共享相同的基类(我称之为
CustomProfileBase
)。此外,配置中进行了以下更改:
app.config
代码
现在,我们已经在相应的数据库中创建了一个用户以及一个配置文件。您可以通过
membershipProvider
检索用户,并通过ProfileManager.FindProfilesByUserName()
检索个人资料。I have resolved this with multiple profiles and providers, using the following hack:
First: create a base class for your profiles. It doesn't have to contain all the fields; it's just important they share the same base class (I called this
CustomProfileBase
).Furthermore the following change in config:
app.config
code
Now we have created a user in the according database along with a profile. You can retrieve the user through the
membershipProvider
and the profile throughProfileManager.FindProfilesByUserName()
.web.config 中不能有超过 1 个配置文件,但一个配置文件可以有多个提供程序,因此也许您应该开始考虑将架构更改为只有 1 个配置文件,甚至可能将它们混合在一起。然后你就会有这种 web.config:
另一种解决方案是根据你的配置文件将你的站点分为 2 个子目录/子应用程序,并在每个子应用程序中使用所需的配置文件创建自己的 web.config。
You can't have more than 1 profile in web.config but a profile can have multiple providers so maybe you should start thinking about changing your architecture to only have 1 profile, maybe even mixing them together. Then you'd have this kind of web.config:
The other solution would be to divide your site in 2 subdirectories/subapplications based on your profiles and in each subapplication create it's own web.config with desired profile.