Sunday, January 30, 2011

Development of a MVC3 Application -- 3 -- Membership Provider Issues for SqlCE

For the MVC3 application we built in Previous Article, as we want our application to be portable and use sdf file as the database for log in as well, we changed the web.config file below:

< add name="ApplicationServices"
connectionString="data source=|DataDirectory|aspnetdb.sdf"
providerName="System.Data.SqlServerCe.4.0" />

See the picture:



There is register and login issues.

Let's goes to the Logon and register page: http://localhost:1414/Account/Register.



When we click "Register", there comes out an exception in AccountModel class:



So what causes this problem? Let's exam the web.config file, and we find the issue:

We will see the memebership provider, profile provider, and rolemanager provider use AspNetSqlMembershipProvider, AspNetSqlProfileProvider and AspNetSqlRoleProvider respectively, and this causes the connection exception.

Instead of re write our own membershipProvider, profileprovider and rolemanagerprovider, we found there have already exists some projects in Codeplex on sql compact asp.net membership provider, so we use the classes directly.

I am not going to write in details, but just follow the instructions in codeplex step by step.

And the Register and login work sucessfully.



You can download my sample code here.

1 comment:

Bibo said...

Hi,
I can´t download source code.
Thanks for help with this