我正在尝试在带有 .Net 框架 4.8 的 Asp.net MVC 中使用 UserSecret。我在通过 UserSecret 访问ConnectionString时遇到问题,原因是我也在使用Membership 提供程序和Entityframework edmx文件。我用来访问连接字符串的以下代码
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="Secrets" mode="Greedy" userSecretsId="b503099f-e1d9-4700-9e50-cf4081a700e3" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</builders>
</configBuilders>
<connectionStrings configBuilders="Secrets">
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="" providerName="System.Data.SqlClient" />
<add name="HIPAADbEntities" connectionString="" providerName="System.Data.EntityClient" />
</connectionStrings>
在我运行应用程序时编写上述代码后,我遇到以下错误
这些是用 web.config 编写的代码行,这给了我错误
<membership userIsOnlineTimeWindow="120">
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="true" enablePasswordReset="false" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Encrypted" maxInvalidPasswordAttempts="25" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
<add name="MyMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="true" enablePasswordReset="false" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Encrypted" maxInvalidPasswordAttempts="25" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
UserSecret文件如下
<?xml version="1.0" encoding="utf-8"?>
<root>
<secrets ver="1.0">
<secret name="LocalSqlServer" value="Data Source=.;Initial Catalog=TestDB;Integrated Security=True"></secret>
</secrets>
</root>
如何访问有权访问连接字符串的会员标签中的 UserSecret?没有 UserSecrets 它工作正常。但我需要让它与 Usersecret 一起使用