Ho appena eseguito il processo e i passaggi sono i seguenti. Presumo si prevede di utilizzare Entity Framework per l'accesso ai dati e lo hanno già impostato:
- librerie di riferimento
WebMatrix.Data
e WebMatrix.WebData
. Troverete loro sotto Assemblee/Estensioni nella finestra Aggiungi riferimento
- Aggiungere le seguenti sezioni in
Web.config
:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=LicenceAudit.mdf;Integrated Security=SSPI;attachDBFilename=|DataDirectory|\LicenceAudit.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<system.web>
<membership defaultProvider="simpleMembershipProvider">
<providers>
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<providers>
<clear/>
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
</providers>
</roleManager>
</system.web>
- Aggiungi
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UsersTableName", "UserId", "UserName", true)
-Application_Start()
in Global.asax.cs
- Assicurarsi che il file di database esiste e contiene la tabella appropriata. La proprietà UserId deve essere di tipo
int
.
- Verificare tutto eseguendo
WebSecurity.CreateUserAndAccount("testUser", "myStrongPassword")
. Se passa, sei in chiaro.
fonte
2013-06-28 19:41:22