我正在尝试创建使用postgresql for database的MVC 3应用程序,并且应该能够使用mono运行在linux中。我计划使用Membership来进行用户管理和身份验证,但在尝试创建新用户时仍然遇到错误。 我正在使用Npgsql作为数据提供者,使用NauckIT.PostgreSQLProvider作为成员资格。 这是我的Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms name=".AspNetAuth" protection="All" defaultUrl="~/Default.aspx" loginUrl="~/Account/LogOn" timeout="3000" path="/" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<machineKey validationKey="AF2DD8866752787D1FAC5DA9EDBDB829EF9D41D4BFFAB47481399D9FBC215C7AC45E4FDF67EF66D374629F047429181C3CCAB1DEDC9BFA0D3F07B1A187D57CB2" decryptionKey="1698432D7389DCF12FC6DDA1C58F7EF7F9A82A9FA330AFFDF69858DCC095D449" validation="SHA1" decryption="AES" />
<membership defaultProvider="PgMembershipProvider">
<providers>
<clear />
<add name="PgMembershipProvider" type="NauckIT.PostgreSQLProvider.PgMembershipProvider" connectionStringName="AspSQLProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" passwordFormat="Hashed" applicationName="member" />
</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="AspSQLProvider" applicationName="member" />
</providers>
</roleManager>
<profile enabled="true" defaultProvider="PgProfileProvider">
<providers>
<clear />
<add name="PgProfileProvider" type="NauckIT.PostgreSQLProvider.PgProfileProvider" connectionStringName="AspSQLProvider" applicationName="member" />
</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="AspSQLProvider" applicationName="member" />
</providers>
</sessionState>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<clear />
<add name="AspSQLProvider" providerName="Npgsql" connectionString="Server=127.0.0.1;Port=5432;Database=pgtest;User Id=user;Password=pass;Encoding=UNICODE;Sslmode=Prefer;Pooling=true;Protocol=3" />
</connectionStrings>
</configuration>
在我的帐户控制器中,我
NpgsqlConnection AspSQLProvider = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["AspSQLProvider"].ConnectionString);
AspSQLProvider.Open();
MembershipCreateStatus createStatus;
NauckIT.PostgreSQLProvider.PgMembershipProvider test = new NauckIT.PostgreSQLProvider.PgMembershipProvider();
test.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
但CreateUser会出错:
缺少连接字符串参数! 参数名称:HOST
我无法让它发挥作用。
任何人都可以指出我做错了什么,我应该怎么做。此外,如果有人有其他好的解决方案,如何用postgresql进行用户管理会很乐意听到它们。