NauckIT.PostgreSQLProvider的问题

时间:2011-09-30 12:41:12

标签: asp.net membership

我遇到了PostgreSQL的AspSQL Provider问题(http://dev.nauck-it.de/projects/aspsqlprovider)。

当我尝试使用ASP.NET网站管理工具创建角色时,此消息不断出现:

您选择的数据存储存在问题。这可能是由无效的服务器名称或凭据或权限不足引起的。它也可能是由未启用角色管理器功能引起的。单击下面的按钮可重定向到可以选择新数据存储的页面。

以下消息可能有助于诊断问题:必须在不在独立exe内运行时指定exePath。 (D:\ Documents \ Programming \ Projects \ Portal \ web.config第40行)

这是web.config部分:

<membership defaultProvider="PgMembershipProvider">
  <providers>
    <clear />
    <add name="PgMembershipProvider" type="NauckIT.PostgreSQLProvider.PgMembershipProvider" connectionStringName="db" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="bp" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="PgRoleProvider" cacheRolesInCookie="true" cookieName=".AspNetRoles" cookiePath="/" cookieProtection="All" cookieRequireSSL="false" cookieSlidingExpiration="true" createPersistentCookie="false" cookieTimeout="30" maxCachedResults="25">
  <providers>
    <clear />
    <add name="PgRoleProvider" type="NauckIT.PostgreSQLProvider.PgRoleProvider" connectionStringName="db" applicationName="bp" />
  </providers>
</roleManager>
<profile enabled="true" defaultProvider="PgProfileProvider">
  <providers>
    <clear />
    <add name="PgProfileProvider" type="NauckIT.PostgreSQLProvider.PgProfileProvider" connectionStringName="db" applicationName="bp" />
  </providers>
  <properties>
    <add name="FirstName" />
    <add name="LastName" />
  </properties>
</profile>
<sessionState mode="Custom" customProvider="PgSessionStateStoreProvider">
  <providers>
    <clear />
    <add name="PgSessionStateStoreProvider" type="NauckIT.PostgreSQLProvider.PgSessionStateStoreProvider" enableExpiredSessionAutoDeletion="true" expiredSessionAutoDeletionInterval="60000" enableSessionExpireCallback="false" connectionStringName="db" applicationName="bp" />
  </providers>
</sessionState>

我按照逐步说明进行操作

提前致谢

2 个答案:

答案 0 :(得分:2)

似乎HttpContext.Current可以为null。 PgMembershipProvider类检查它以查看它是否托管。根据答案,它会尝试OpenExeConfiguration(对于独立)或OpenWebConfiguration用于Web托管应用程序。

由于HttpContext.Current有时在Asp.Net 4.0中为空,因此做出了错误的决定,并且在Web应用程序中调用了OpenExeConfiguration(大禁忌)。修复方法是更改​​PgMembershipProvider.Init以使用以下检查:

Configuration cfg = HostingEnvironment.IsHosted ? 
    WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath) :
    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

而不是HttpContext.Current != null检查。

答案 1 :(得分:0)

此错误已在2.0.0版本的提供程序中修复。

请参阅http://dev.nauck-it.de/issues/131

您可以通过NuGet下载最新版本:https://nuget.org/packages/NauckIT.PostgreSQLProvider/