我正在尝试按代码初始化SQL成员资格提供程序,一切都在第一个请求中正常工作! 当下面的代码再次执行时(例如刷新页面后)我收到以下错误 :
属性“connectionStringName”缺失或为空。
页面加载代码:
MembershipSection membershipSection = (MembershipSection)ConfigurationManager.GetSection("system.web/membership");
string sqlProviderName = "AspNetSqlMembershipProvider";
NameValueCollection providerConfig;
providerConfig = membershipSection.Providers[sqlProviderName].Parameters; // returning empty list in the second request
var _SqlProvider = new SqlMembershipProvider();
_SqlProvider.Initialize(sqlProviderName, providerConfig);
的Web.config:
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Encrypted" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" applicationName="/" />
</providers>
</membership>
任何建议?
答案 0 :(得分:0)
如何将数据/ connectionstring / obj保持在静态级别(如单例)?
它不像在整个Web实例中都会改变连接字符串,是吗?
static string/dataType _DataToBeRead1timeOnly = null;
static string/dataType DataToBeRead1timeOnly
{
get {
if (_DataToBeRead1timeOnly == null) { _DataToBeRead1timeOnly = .... }
return _DataToBeRead1timeOnly;
}
}