Scott Hanselman

Introducing System.Web.Providers - ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQL Compact and SQL Azure

June 16, '11 Comments [65] Posted in ASP.NET | ASP.NET MVC | NuGetPOW
Sponsored By

UPDATE #2: Note that the NuGet package has changed its name from System.Web.Providers to Microsoft.AspNet.Providers.

UPDATE: Note that in MVC 4 and ASP.NET 4 and 4.5 the default hash is now HMACSHA256

Crazy random logo of evocative clipart combining the .NET Logo and some universal powerplugs into an unofficial logoI always like to remind folks of the equation ASP.NET > (ASP.NET MVC + ASP.NET WebForms). The whole "base of the pyramid" of ASP.NET has lots of things you can use in you applications. Some of these useful bits are Session State, Membership (Users), Roles, Profile data and the provider model that underlies it. Using these isn't for everyone but they are very useful for most applications, even ones as large as the ASP.NET site itself.

Today the Web Platform and Tools team (WPT) is  releasing an Alpha of the ASP.NET Universal Providers that will extend Session, Membership, Roles and Profile support to SQL Compact Edition and SQL Azure. Other than supporting additional storage options, the providers work like the existing SQL-based providers.

Today these are being released via a NuGet Package, but it's very likely that these Universal Providers will be the default in the next version of ASP.NET.

To enable the providers, the NuGet package adds configuration entries in the web.config file. The configuration for these providers is the same as the existing SqlMembershipProvider class, but the type parameter is set to the type of the new providers, as shown in the following table:

SQL Provider Types Equivalent Type for Universal Providers
System.Web.Security.SqlMembershipProvider System.Web.Providers.DefaultMembershipProvider
System.Web.Profile.SqlProfileProvider System.Web.Providers.DefaultProfileProvider
System.Web.Security.SqlRoleProvider System.Web.Providers.DefaultRoleProvider
(Built in provider) System.Web.Providers.DefaultSessionStateProvider

If you install these, the NuGet package will swap your defaultProviders in your web.config. You can certainly pick and choose the settings for each as well. Here we're changing Profile, Membership, RoleManager and SessionState. The latter is nice as it better allows your session-state-using Azure apps to scale with SQL Azure as the backend storage.

Install-Package Microsoft.AspNet.Providers

Using these Universal "Default Profile Providers" means all you have to do is set the right connection string and your  applications that use these services will work with SQL Server (plus Express), SQL Server Compact and SQL Azure with no code changes from you.













enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />













Selecting a Data Store

By default, the NuGet package sets the connection string to use a SQL Server Express database (wrapped here for readability):

"Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnetdb.mdf;
Initial Catalog=aspnet;Integrated Security=True;
User Instance=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"

If you want to use SQL Server Compact, change the connection string as shown in the following example:




If you want to use SQL Azure, change the connection string like this example (wrapped for readability):


providerName="System.Data.SqlClient"/>

Even though this release is primarily about extending support to all versions of SQL Server, I realize that y'all might not even know about what these things do, so I thought I'd spend a little time explaining. I notice also that there's some confusion on StackOverflow and other sites on how to use Membership and Profile and the like on ASP.NET MVC, so I'll use that for the examples.

Example of Membership, Roles and Profile in ASP.NET MVC (with the Universal Providers)

I'll fire up VS and File | New Project on a new ASP.NET MVC 3 Project. Then I'll right click on References and select Add | Library Reference. The NuGet package id is "Microsoft.AspNet.Providers." After this package is installed, I can also install SQL Compact Edition via NuGet if I like and set the connection string to SQL Compact as shown above.

Remember, this is a very functional Alpha, but there may be bugs (report them!) so it might be updated a few times before the next version of ASP.NET is released.

First, I'll run my app and click Register and make a new user named "Scott."

Making a new user

Adding Roles to a User

Next, from Visual Studio Project menu, I visit ASP.NET Configuration. (I could also write my own admin section and do this programmatically, if I liked).

Selecting ASP.NET Configuration site from the Project Menu

Then from the Security tab, under Roles, I'll create a new Role:

image

Then I'll find the Scott User and add him to the Administrator Role:

Giving the Scott User Administrator Role

I want to show something if a user is an Administrator. I'll add a little chunk of code to the default website's _LogOnPartial. cshtml so we'll see [Administrator] next to their name of they are one.

Welcome scott (Administrator)

I'll add a small line where I ask "User.IsInRole()" like this:

@if(Request.IsAuthenticated) {
Welcome @User.Identity.Name
@(User.IsInRole("Administrator") ? "(Administrator)" : String.Empty)
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]

}
else {
@:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
}



@if (ViewBag.Profile != null) {
Hey, your birthday is @ViewBag.Profile.Birthdate.ToString("d")! Congrats.
}

So now I have some Roles I can assign to users and check against. I can set whatever roles I want, like Bronze, Silver, Gold, etc.

Adding Profile Information to Users

Let's say I want Users to have a Birthday and I want that to be part of the User Profile. I can just use the Profile object and ask for things via string like this:

DateTime? birthday2 = HttpContext.Profile["Birthdate"] as DateTime?; //alternative syntax

However, perhaps I'd rather have a stronger typed syntax for my profile.

NOTE: I've already brought up the issue that User hangs off Controller in MVC 3 but Profile is simply missing. Perhaps that will be fixed in MVC 4. I believe it was a oversight. You shouldn't be digging around in HttpContext if you want your code testable

I'll make a small CustomProfile object like this that extends ProfileBase:

public class MyCustomProfile : ProfileBase
{
public DateTime? Birthdate {
get { return this["Birthdate"] as DateTime?; }
set { this["Birthdate"] = value; }
}
}

Alternatively, I could put the "getting" of the profile in the custom class in a static, or I could use Dependency Injection. It depends on how you want to get to it.

public static MyCustomProfile GetUserProfile(string username)
{
return Create(username) as MyCustomProfile;
}
public static MyCustomProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as MyCustomProfile;
}

Then in web.config, I'll update the so the system know the derived Profile class I want used when I ask for one:


...

For older website projects, I can add properties in the web.config like this. There are attributes I can use like SettingsAllowAnonymous for custom derive classes in code.

..



Or I can even use IIS7's administration interface to edit the profile details in the web.config. You can have all kinds of profile properties, group them and it's all handled for you.

Using IIS Manager to edit User Profile schema

If I like, I can ask for the User's Profile (I've got it set for only authenticated users), and set a default as well. I save explicitly, but there is an auto-save option also.

if (User.Identity.IsAuthenticated)
{
var customProfile = HttpContext.Profile as MyCustomProfile;

DateTime? birthday = customProfile.Birthdate; //Because I made a strongly typed derived class

if (!birthday.HasValue) {
customProfile.Birthdate = new DateTime(1965, 1, 14); //cause that's everyone's birthday, right?
customProfile.Save(); //or set autosave if you like.
}

ViewBag.Profile = customProfile; //So the View can use it
}

At the very end I put the Profile in the ViewBag so it can be accessed from the View. I could also have added just the things I want to a larger ViewModel. Then I can use it later with some sanity checks:

@if (ViewBag.Profile != null) { 
@:Hey, your birthday is @ViewBag.Profile.Birthdate.ToString("d")! Congrats.
}

Expect to see more cloud-ready things like this in the coming months that'll better position your apps, new and old, to move up to Azure or even down to SQL Compact. Hope this helps. Enjoy.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Friday, June 17, 2011 2:19:59 AM UTC
Hmm, have you guys done anything to address the issues Mark Seeman raises regarding this provider... thing? From what I can see from the sample code, not so much... But I know you have a lot of concern for testability, so maybe I'm missing the hooks you've added.
Friday, June 17, 2011 2:37:44 AM UTC
what kind mechanism or strategy for encrypt connection string or part of provider setting for this library?
Friday, June 17, 2011 4:40:57 AM UTC
Very slick. I was just working on a small prototype app the other day that needed authentication. I didn't have SQL Server installed on the machine. Tried to quickly hook up the Membership Provider to SQL Compact and was honestly surprised when I hit a brick wall.

Is this code going to be open source?
Friday, June 17, 2011 5:34:58 AM UTC
Is there a direct download available? I'd like to check it out in a disassembler without creating a new visual studio solution.

sorry in advance for the double post
fschwiet
Friday, June 17, 2011 6:25:10 AM UTC
dede - You can use the same connection string encryption that ASP.NET supports already, or use integrated security.

Shawn - Lemme ask.

fschwiet - Sure, just download the NuGet manually and unzip it. It's right there.
Friday, June 17, 2011 6:27:03 AM UTC
Hum... thought I saw SQL at first glance. Took me a moment to realize it was entity sql.

Are there plans to support other providers and databases? EF Code First support?

lynn
Friday, June 17, 2011 8:27:37 AM UTC
Very nice!
Friday, June 17, 2011 8:36:20 AM UTC
Thanks for great news and examples. Wanted to ask if there is also support for Azure table storage planned?
Friday, June 17, 2011 8:45:33 AM UTC
thanks Scott on the answer.
what I am thinking is may be it is time to have 'provider crypt' for custom encrypt per-site.
Current asp.net way doing it require administrator.
how about on share hosting? most the time we do our implementation of the provider.
And I am think this happen on desktop environment too.
Like on EF, we must inherit the context to do de-crypt connection string or add de-crypt connection-string on context each time we instance the context.
why we can have provider-like way on framework? (crypt, logger, trace, (may be notify provider(just like mobile -- implementation can be for web(form/mvc) and desktop(winform/xaml)) for example) it is just an idea, for most this we common thing we did.
so, team EF, asp.net or other teams can use it and we developer can consume and focus on our main task.
Keep amaze us :) thanks.
Friday, June 17, 2011 10:54:06 AM UTC
Is this SQL only? Or maybe EF only? Because I'm not such a big fan of EF and the SQL its generating.
Edward
Friday, June 17, 2011 12:19:13 PM UTC
That's a pretty gutsy move to name the actual classes DefaultXXXXXXXXXProvider. That's just going to cause a lot of confusion down the road.

I'll also echo Domenic's point - I don't even use providers anymore b/c they are a pain for testability.
Friday, June 17, 2011 6:20:09 PM UTC
The user in the controller is an IIdentity, not a MembershipUser. Controller.User (of type IIdentity) is completely appropriate because that's the generic authentication mechanism. Controller.MembershipUser or Controller.Profile definitely isn't appropriate as that inflicts a lego block on those of us that don't use it.

To that end, even Controller.User (IIdentity) is a mixed bag as it can easily stymie testability of the controller action. I'd rather see an IIdentityValueProvider similar to the HeaderValueProvider created by Donn Felker. Perhaps to that end, a MembershipUserValueProvider and a ProfileValueProvider would be a better choice than Controller.MembershipUser and Controller.Profile properties.
Rob
Friday, June 17, 2011 7:27:58 PM UTC
@Rob: or, instead of contorting yourself to follow this provider thing, you could just request an IIdentity as part of your controller's constructor, thus gaining the benefits of the "D" in "SOLID."
Friday, June 17, 2011 7:37:08 PM UTC
@Domenic: I was thinking taking in an IIdentity as a parameter in the Action, maintaining the controller's statelessness. How do you get the IIdentity into the constructor parameter? Is this a feature of your chosen IoC? Which IoC do you use?
Rob
Friday, June 17, 2011 8:48:38 PM UTC
@Rob: Your point about statelessness is well-taken, so now I'm not so sure that's the way I would do it. (Although, realistically, most people don't build there web apps to be stateless.) But to answer your questions, I use AutoFac. In general though, with most containers it's not hard to register IIdentity to map, on a per-request basis, to an appropriate concrete instance. Something like:

builder.Register(c => HttpContext.Current.User.Identity).As<IIdentity>().HttpRequestScoped();
Saturday, June 18, 2011 11:22:16 AM UTC
Actually this is not a equation :ASP.NET > (ASP.NET MVC + ASP.NET WebForms). To be a equation, something have to be equals to another. like that: x=y+z.
redney
Saturday, June 18, 2011 9:51:59 PM UTC
For my question, viewing the DLL without creating a project, I found Nuget package explorer to work nicely: http://nuget.codeplex.com/releases/view/59864

Getting back to the membership provider... I see they've duplicated the internal class SecUtility for parameter validatoin (and related string resources). Did they put the source up anywhere? Its kind of sad anyone wanting to do a membership provider with matching parameter validation has to redo that code.
fschwiet
Sunday, June 19, 2011 10:50:46 PM UTC
Just wondering if these providers can be backed by OData or some WCF service. I have already done a work around, but will be nice if we get some sort of out of the box contracts which we can implement.
satjinder
Monday, June 20, 2011 4:44:11 PM UTC
Well, in the era of ORM and IoC I don't think the User related Providers would bring anything except frictions. Anyone who tired to map these providers objects to actual domain objects knows the pain points, too much plumbing code is required.

Monday, June 20, 2011 7:49:50 PM UTC
Could you show a real example switching from Compact to Express to SqlAzure ?
Thank you,
Monday, June 20, 2011 8:20:22 PM UTC
Cool, thanks Scott!

Do you know how they got around the issue of SQL Azure not being able to do timed jobs, and thus, it couldn't self-invalidate expired sessions? I've implemented it with two other suggested methods using TableStorage: http://www.intertech.com/Blog/post/Session-State-in-Windows-Azure.aspx and paying extra to use a worker role to call an SP in SQLAzure: http://blogs.msdn.com/b/sqlazure/archive/2010/08/04/10046103.aspx but both felt a little hack-ish.

I'd love to find out how they did it and if it 'just works' like it does in SQL Server.
Thanks!
--Aaron
Monday, June 20, 2011 9:42:54 PM UTC
Aaron - Currently the idea is that it'll check for expired sessions pigging-backing on activity. It's checking as things are happening.

Ignat - You mean, like taking an existing site running on IIS and Compact and upgrading it to Azure?

redney = Um, ok, an expression, then.
Monday, June 20, 2011 10:27:33 PM UTC
Thanks Scott!

So I'm guessing that they're doing something to clear expired sessions every time any user requests a session or membership object? Any performance implications of all that? I've seen others suggest custom writing a clean up call every page load (in a site Master page) to avoid paying for a worker role instance, but that's a real hack (see 4th comment down: http://blogs.msdn.com/b/sqlazure/archive/2010/08/04/10046103.aspx)

Also, is there a quick way to set up those table on Azure like there is on a full SQL Server ala aspnet_regsql.exe? I've been running that local on Express and using SQL Azure Migration Wizard (http://sqlazuremw.codeplex.com/) to move it to the cloud.
Tuesday, June 21, 2011 9:27:24 AM UTC
Yes. Let's say you have a site on SqlCompact , with some users registered. Migrate the Compact to Express, modify web.config. Works.
Same from Express to Azure ( with pure Tables, please , not SqlAzure...)
Tuesday, June 21, 2011 6:55:02 PM UTC
@Ignat, I don't quite understand your last part "with pure Tables, please, not SqlAzure..." ? Are you suggesting using TableStorage instead of SQL Azure? In Scott's example in the blog he's got the connection string set up to go to SQLAzure.

--Aaron
Tuesday, June 21, 2011 10:12:11 PM UTC
Is there a way to use this with an ODBC connection ? I get the following error.

A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'System.Data.Odbc.OdbcConnection'. The store provider might not be functioning correctly.

Which I suspect is because I'm using Web Forms and not MVC. Any help would be appreciated.
Wednesday, June 22, 2011 3:53:39 AM UTC
Awesome. This is much needed. Marry me, Scott.

To answer to the question about scripts above, if you specify a new db name in the connection string, the both the database and the membership tables will be created for you.
Wes
Wednesday, June 22, 2011 6:55:59 AM UTC
An example with Azure tables would be perfect.
Thursday, June 23, 2011 6:58:26 PM UTC
Scott, any word on including the simple API of SimpleMembership? I am jumping through hoops to get SimpleMembership working with MVC, just to get to the great API.
Tuesday, June 28, 2011 3:25:04 PM UTC
Is it possible to have dual authentication?

Level 1: Auto authenticate using active directory or display a login id and password for a database authentication?

-Hem
Wednesday, June 29, 2011 5:54:34 AM UTC
I can address a couple of the questions asked here. The Alpha release of the providers support SQL Server, SQL Compact and SQL Azure, given a connection string to one of these databases it will just work. Technically they should also support any database that Entity Framework supports such as MySQL and Oracle but we have not tested these at this time. They were written using Entity Framework specifically to allow us to support multiple databases with a single implementation.

We plan to have an update in the future (Beta?) that will also support Azure Storage and the File System providing even more flexibility for our customers.

Next some of the feedback that we receive about the existing ASP.NET providers is that they are hard to use with you own database schema if you want to control the profile table for example. We are working to address this as well but the main goal of this release was to quickly provide a set of providers that support our existing infrastructure and work well in Azure.
Wednesday, June 29, 2011 5:34:12 PM UTC
Site breaks if using ADD DEPLOYABLE DEPENDENCIES (adding the RAZOR SYNTAX option seems to be the killer) - unless I'm doing something completely wrong. Is this known? Whats' the Fix?
----------------------
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: This method cannot be called during the application's pre-start initialization stage.

Source Error:
Line 31: <clear/>
Line 32: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
Line 33: <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
Line 34: </providers>
Line 35: </membership>

Source File: c:\xxx\web.config Line: 33
Wednesday, June 29, 2011 11:13:05 PM UTC
What about using these configurable providers to switch between ACS and Forms auth?

Both may have group/role membership, if configured, and I'd like to have common code to query this.

(I won't even mention the possiblility of on-site deployment models with AD Windows authentication)
Monday, July 04, 2011 5:04:20 AM UTC
How about SQL Server Web Event Provider?
Wednesday, July 06, 2011 12:41:17 AM UTC
I tried using this against a blank database and it is creating a Profiles table when I don't have any ProfileProvider defined in web.config; only Membership and Role providers are defined. This prevents it from being used with a database that has an existing "Profiles" table. The error given on WAST when accessing the Security tab is "An error occurred while executing the command definition. See the inner exception for details."
tom
Wednesday, July 06, 2011 12:42:17 AM UTC
^that should be WSAT (ASP.NET WebSite Administration Tool), not WAST
tom
Wednesday, July 06, 2011 8:54:09 PM UTC
Please change the provider model so I can use the email as index and not the username ...
Friday, July 08, 2011 3:58:24 PM UTC
Is there a way to use this in a WPF app? I keep getting the exception:
Could not load type 'System.Web.Providers.DefaultMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Saturday, July 09, 2011 8:31:00 PM UTC
Works great. I just created a new project with VS2010 and switched the connection string to my SQL CE 4 database and created a new user.

Greate Job.
Sunday, July 10, 2011 8:33:32 PM UTC
Got it working in terms of authentication but getting error creating user: Getting an Object Reference Not Set to an Instances of an Object. Looking at the stack trace seems to be generated at System.Web.Providers.Entities.ModelHelper.CreateEntityConnection(ConnectionStringSettings setting, String csdl, String ssdl, String msl) Any ideas?
Sunday, July 10, 2011 9:31:23 PM UTC
There seems to be some issue reading the config when creating a new DefaultMembershipProvider object. I found it necessary to call the following: System.Collections.Specialized.NameValueCollection config = new NameValueCollection();
config.Add("connectionStringName", "DefaultConnection");


member.Initialize("DefaultMembershipProvider",config);
Wednesday, July 27, 2011 11:10:02 AM UTC
got excited about this, but still we have default Profile objects being saved as blobs in the database. With the advent of EFCF, POCO and Scaffolding, how have we not come to a simple solution for binding a custom Profile table out of the box ?

Please, please, please give this some consideration, having profile items associated against the user shouldn't take such a massive amount of code to STILL end up putting them in the same constrained, non queryable, state that they have been in for sooooo long...

thanks for listening to yet another gripe....

btw, loving .net MVC3, nuGet and everything that has come out recently and understand you can't cover everything (like Profile object still being in HttpContext !!!)
Monday, August 08, 2011 5:26:27 PM UTC
Do you have any details on the System.Web.Proivders.Entities?
I would really like to use these to access the underlying data source but have yet to do so.
I have been having difficulty using ObjectContext and DbContext and would like to know if there is some way to have a context made without having to alter my connection string.
Thanks.
Thursday, August 11, 2011 6:10:51 PM UTC
package just updated to v 1.0 last night
Nuget Site
Thursday, August 18, 2011 5:07:31 AM UTC
What is the best way to 'transfer' the existing user data (including membership, role & profile) created by the old SqlMembershipProvider (i.e, the tables and stored procedures generated by aspnet_regsql.exe) to the new tables generated by the new Universal Providers?
Tuesday, August 23, 2011 5:01:50 PM UTC

HI,

The session provider of ASP.NET Univarsal Providers is interesting approach, but a performance decreases to remove its expired sessions.
We made custom session provider inherit from System.Web.Providers.DefaultSessionStateProvider, and override some method.
The custom session provider(we made!) added index to an 'Expires' column, and remove expired sessions collectively in ExecuteNonQuery. Because of that, we improve a performance of the custom session provider.
Could you improve the official Universal Provider by refering to our session provider code?

see also: http://tinyurl.com/3tbgys5
Thursday, August 25, 2011 2:51:11 PM UTC
I tried SQL Server Compact, but have problems when I deploy the membership database. Users I create at my local machine (with "ASP.NET Configuration"), will not be allowed to log in after publishing the application to a web site. Users created at the publish site are OK.
Any suggestion for a fix?
Friday, August 26, 2011 11:43:41 AM UTC
I'd like to use a single connection string for our EF-based application and DefaultSessionProvider, but the provider breaks if the connection uses the System.Data.EntityClient provider.

The error message is: "Unable to find the requested .Net Framework Data Provider. It may not be installed. "
Jake
Friday, August 26, 2011 11:48:07 AM UTC
I forgot to add that apparently it is impossible to use Azure ServiceConfiguration files to define the connection strings (?). Web.config values can't be changed in Azure without upgrading the whole package so it would be better to define the connection string in the Azure config file.
Jake
Friday, August 26, 2011 7:13:50 PM UTC
The problem I had with membership in SQL Server Compact solved.
I had to set the "HashAlgorithmType Attribute" in web.config like this:
<membership hashAlgorithmType="SHA1">
<providers>....</providers>
</membership>
It also works with hashAlgorithmType="HMACSHA256".
More tips on: http://www.codeproject.com/KB/aspnet/LoginControlError.aspx
Tuesday, September 06, 2011 7:08:05 PM UTC
Hi Scott,

Just a note that in your examples of changing the connection strings, you use the names Sql_CE and Sql_Azure but if you want them to work with the default names added by the System.Web.Providers package, you should keep the connection string name as DefaultConnection and just alter the other conneciton string properties accordingly. Otherwise, you'd have to update the connectionStringName property of the provider entries to Sql_CE or Sql_Azure, etc. I know this is pretty obvious but might throw off some people.
Saturday, September 24, 2011 5:44:30 AM UTC
Sounds great. What would be extremely helpful would be if the azure implementation actually could get it's connection string from cscfg, so that you can put different values in there for staging/production etc, and not have to redeploy to change them. Doable?
Saturday, October 01, 2011 4:28:09 AM UTC
The DefaultProfileProvider seems fail under Medium trust in Mvc. When i try to read the profile value in HttpContext.Profile["MyKey"] the System.Security.Permissions.SecurityPermission deny.
Wednesday, November 02, 2011 4:51:11 PM UTC
I'm getting this to work on my workstation, but when I publish my project to Azure I can login, but the access rules doesn't seem to work.

Anyone else having this issue? And idea's how to fix it, workarround?
Wednesday, November 02, 2011 11:15:22 PM UTC
I get a "version 661" error after I created a small test MVC 3 project and included the SQL Compact Ed 4.0 and System.Web.Providers Nuget package and "Added Deployable Dependencies" and published from my Windows 7 box to my Windows Server 2003 SP3 with .Net 4.0 and ASP.NET MVC 3, and I get an error.

Error: "The database ...App_Data\ASPNETDB.MDF cannot be opened because it is version 661. This server supports version 612 and earlier. ..."

Any ideas how to get this to work on boxes that don't have the necessary dependencies?

Thanks.
Tuesday, November 22, 2011 6:26:57 AM UTC
Can this be made to work with SimpleMembership for MVC3? Anything needed to be done? Would be a great combination.

http://anderly.com/2011/08/11/using-simplemembership-in-mvc3/comment-page-1/#comment-2797
drewid
Wednesday, December 28, 2011 4:15:04 AM UTC
Works well initially. But I notice that this creates an ASPNETDB.MDF for no clear reason. Then I get all sorts of weird messages when using the ASP.NET configuration pages, as those write stuff to my Compact database and stuff elsewhere, presumably to that other database but I have no idea why. Any idea?
Friday, January 27, 2012 3:34:51 AM UTC
Great package. Thanks!
Mickey
Thursday, February 02, 2012 6:10:53 PM UTC
i am using DefaultSessionProvider however i get an excpetion saying "Can not connect to database master" in SQL Azure. The same connection string works for my toher database related activities.
Wednesday, February 22, 2012 3:50:09 PM UTC
Gotcha: MultipleActiveResultSets=True is case-sensitive!
Monday, March 05, 2012 4:14:19 AM UTC
Just to confirm your note:

"NOTE: I've already brought up the issue that User hangs off Controller in MVC 3 but Profile is simply missing. Perhaps that will be fixed in MVC 4. I believe it was a oversight. You shouldn't be digging around in HttpContext if you want your code testable"

Profile does indeed hang off of Controller in MVC 4.
Monday, September 17, 2012 10:18:30 PM UTC
Thanks for your article
But I have search all over the internet to resolve the situation below :

How to Handle the initialization when Simplemebership and context share the same database and the same context ? (code first)

I have a Database and I want to store the simplemembership information and my domain model tables too. But how to Initialize them at the same time and seeding them ?

This seems to be impossible

Thanks
Hassan
Tuesday, September 25, 2012 2:42:05 AM UTC
I would highly recommend looking at the new SimpleMembershipProvider and SimpleRoleProvider if you would like full control of the User table and fields.

Here is a link with full integration with SimpleMembershipProvider and SimpleRoleProvider.

http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-codefirst-and-custom-user-properties/
Tuesday, September 25, 2012 8:27:38 PM UTC
Hi Scott, it seems that someone forgot to allow writes to "PropertyValueBinary" in the Profile Provider. Why isn't it supported? Or am I missing something?
Richard C
Thursday, September 27, 2012 6:01:25 PM UTC
Is there an equivalent to the aspnet_regsql.exe for the new System.Web.Providers framework?

How are the DB Tables created when a new user is created? I need this function for an application I wrote and I'd like to update it for the new framework.

Thanks.
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.