将 ASP.NET 成员资格 web.config 设置移至数据库 这可能吗?

发布于 2024-12-17 14:36:03 字数 706 浏览 0 评论 0原文

我希望对此能得到富有成效的答案。我应该如何将 web.config 中为 asp.net 成员资格提供的设置移动到数据库中以进行跨应用程序自定义。例如会员信息包括如下

  <providers>
    <add 
      name="OdbcProvider" 
      type="Samples.AspNet.Membership.OdbcMembershipProvider" 
      connectionStringName="OdbcServices"
      enablePasswordRetrieval="true"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="true" 
      writeExceptionsToEventLog="true" />
  </providers>
</membership>

额外的

.NET 2.0

ASP.NET 2.0

相关

移动ASP.NET 成员身份特定设置到单独的配置文件

I am hoping for fruitful answer to this. How should i move the settings provided in web.config for asp.net membership into a database for cross application customization. For example membership information include below

  <providers>
    <add 
      name="OdbcProvider" 
      type="Samples.AspNet.Membership.OdbcMembershipProvider" 
      connectionStringName="OdbcServices"
      enablePasswordRetrieval="true"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="true" 
      writeExceptionsToEventLog="true" />
  </providers>
</membership>

Extra

.NET 2.0

ASP.NET 2.0

Related

moving asp.net membership specific settings to a separate config file

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

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

发布评论

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

评论(1

空城之時有危險 2024-12-24 14:36:04

是的,你可以!我们已经成功地做到了这一点。

您可以通过多种方式来完成此操作,一种是将您需要的任何属性注入到提供程序的实例中(此示例假设您正在使用 SqlMembershipProvider 并显示如何注入连接字符串,但是您可以您可以查看 OdbcMembershipProvider 的源代码,了解自己在哪里执行此操作):

public static void InjectConnectionStringIntoSqlMembershipProvider(SqlMembershipProvider provider, string connectionString) {
    Type t = typeof(SqlMembershipProvider);
    FieldInfo fi = t.GetField("_sqlConnectionString", BindingFlags.NonPublic | BindingFlags.Instance);
    if (fi == null) throw new InvalidOperationException("Invalid private identifier.");
    fi.SetValue(provider, connectionString);
}

或者,您可以通过创建继承 MembershipProvider 的类来创建自己的提供程序。

或者,正如 @Andomar 的链接所建议的,您可以从 MembershipProvider 的任何实现(例如 SqlMembershipProvider 等)继承,以获得您想要的内容。

多年来我们已经完成了这三项工作,具体取决于需要多少定制。

Yes, you can! We have done this successfully.

You can do it in a few ways, one is to inject whichever properties you need into an instance of the provider (this example assumes you are using SqlMembershipProvider and shows how you can inject the connection string, but you can take a look at the source of OdbcMembershipProvider to get an idea where to do this yourself):

public static void InjectConnectionStringIntoSqlMembershipProvider(SqlMembershipProvider provider, string connectionString) {
    Type t = typeof(SqlMembershipProvider);
    FieldInfo fi = t.GetField("_sqlConnectionString", BindingFlags.NonPublic | BindingFlags.Instance);
    if (fi == null) throw new InvalidOperationException("Invalid private identifier.");
    fi.SetValue(provider, connectionString);
}

Or, you can create your own provider by creating a class that inherits MembershipProvider.

Or, as the link from @Andomar suggests, you can inherit from any implementation of MembershipProvider (such as SqlMembershipProvider, amongst others), to get what you want.

We have done all three over the years depending on how much customisation was required.

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