Pages

Monday, September 24, 2012

Visual Studio 2012 uses SimpleMembership as its new Membership Provider

Simplified approach to implementing Forms Authentication in MVC 4 Web-apps in VS 2012


(This is the 1st of a 3-article series, on using SimpleMembership along with customized fields)
Article 1: This article

Feature highlights

  • Schema gets built directly - no more aspnet_regsql.exe (or  aspnet_regsqlazure) needed;
  • Much simplified as compared to the earlier membership provider;
  • Usable both for SQL Azure as well as on-premises databases;
  • Supports OAuth/OpenID, to authenticate users through Facebook, Google etc.
  • Easy customization: Adding custom fields to your MVC 4 Registration System

The most interesting details of SimpleMembership

Visual Studio 2012, launched August 15th, uses the new (and very appropriately named) SimpleMembership as its default forms-authentication membership provider for MVC 4 Web Applications, replacing the ASP.NET Membership Provider that all of us have been using for many years. This is a very welcome change. Some of the most interesting changes that we see immediately in this are:

  • Highly simplified database schema - has just 5 tables, no Views, and no stored procedures.
  • Does not use the aspnet_regsql.exe command line tool to generate the schema. Rather, the tables are generated automatically the first time you add a user into the system (through your application). The database used is whatever you set in the connection string in your web.config file.
  • The same approach can be used to create the Membership system in Windows Azure, simply by giving the correct connection string in web.config. Since there are no stored procedures and Views to worry about, the system is just a set of tables that is easily synchronizable between your SQL Azure database and your on-premises database.
  • Another plus for Azure users: now you don't have to worry about the aspnet_regsqlazure tool any more, because the tables are generated by the new system itself.
  • The UserId is now an int column, not a Guid that was used in the previous ASP.NET Membership system. This simplifies the system even more, and reduces space requirement a bit. Please note, however, that you may have to pay attention to this if you need to merge data from 2 separate implementations of the SimpleMembership provider, else there may be key duplication conflicts.
  • Supports user authentication through their Facebook, Google, Microsoft Live, Twitter etc accounts, by simple changes in the AuthConfig.cs file in your project (for details, please visit: OAuth/OpenID Support for WebForms, MVC and WebPages).

A quick VS 2012 web project to check out SimpleMembership

    1. Create a new ASP.NET MVC 4 Web Application, and call it, say, SimpleMembershipTest.

      2. On the next screen, select Internet Application, and create your new project.


      3. Once the new project is created, it's a good idea to update all your NuGet packages - do this by clicking on Tools \ Library Package Manager \ Manage NuGet Packages for Solution, and then selecting Updates > All. Update each of them one by one by clicking on the Update button. (Note - all the DotNetOpenAuth packages will get updated when you simply update the first one.)


      4. In the new project's web.config file, change the connection string for DefaultConnection reflect your server, database and relevant db user info. If you specify the "sa" user, even the database itself can be created by your app, however this obviously does not represent best practices.


      5. Now press F5 or Ctrl-F5 to run the app, and click the Register button - specify a new user id and password and voila! Your new database schema gets created, along with a data row for the new user! And do notice that it's very lightweight - no SPs and no Views


      6. Select data rows from the tables, and you'll see the new user has been created there.


      Happy coding!

      (This is the 1st of a 3-article series, on using SimpleMembership along with customized fields)
      Article 1: This article

      Wednesday, September 19, 2012

      Using VSS 2005 with Visual Studio 2012

      It's easy to integrate Visual SourceSafe into Visual Studio 2012

      Visual Studio 2012, launched on 15th Aug 2012, is a terrific IDE. While most of its documentation includes references to using Team Foundation Server (TFS) integration as the source control, it remains very easy to use VSS 2005 instead, by using the VSS plug-in to get a seamless experience.

      This is extremely useful to those of us who have, for years, been using Visual SourceSafe 2005 with Visual Studio 2010, are happy to be in the comfort zone, and find it simpler to stick to VSS until absolutely forced to move.

      Steps to follow:

      A. Select VSS as the plug-in:

      1. Make sure the VSS 2005 client is installed on your machine. If you have been using it with your VS2010 installation, then it's already there.
      2. In VS2012, go to TOOLS > Options
      3. The Options window will come up. In this window, expand "Source Control" on the left pane, and click on "Plug-in Selection". You should see the following choices in the dropdown (which may vary depending on what other source control plugins you have available on your machine): None, Visual Studio Team Foundation Server, Microsoft Visual SourceSafe, and Microsoft Visual SourceSafe (Internet)
      4. Select Microsoft Visual SourceSafe from the dropdown
      5. (Do not click the OK button at this stage)

      B. Next, adjust the VSS environment settings, if necessary:

      1. Under Source Control in the left pane, click on "Environment"
      2. Make sure that "Visual SourceSafe" shows in the dropdown selection in the right pane, then look through all the settings to make sure they are as desired. For most cases, the defaults should be fine.
      3. (Do not click OK even now!)

      C. Finally, make sure the VSS-specific settings are correct:

      1. Under Source Control in the left pane, click on "Plug-in Settings"
      2. Make sure the VSS login id is correct
      3. Click on the "Advanced..." button, and examine each tab of the resulting "SourceSafe Options" window to make sure everything is as expected. Click OK in that window once you're done.
      4. Click OK in the "Options" window, to save your selection.
      Specifying VSS 2005 as your source control for VS 2012 is now complete. You should now be able to right-click on any solution in the Solution Explorer, and select "Add Solution to Source Control". This would display the VSS log-on window, and enable you to take it from there.

      Once your solution is in VSS, with the correct settings, you'll find most activities to be highly simplified: Starting to edit a file automatically checks it out, right-clicking gives options such as save changes, compare versions, or undo a checkout, and so on.

      Check it out!