Recently I put out a simple NuGet package: MyCouch.AspNet.Identity, that lets you store ASP.Net identity data in CouchDb or in the cloud using Cloudant, instead of in a SQL Server using Entity framework. It’s about a three-five minute change and it is really easy. And to show you this, I have put together a small screencast as well as a small sample, which you can find in this article.


Note. This is so far a pre v1.0.0 product.

There is a simple sample in the repository, that makes use of a local CouchDb install. It requires:

  • database: aspnet-identity
  • an user named: demowith the password: p@ssword.

You see this in Global.asax.

The sample is a basic ASP.Net MVC5 application, where Entity framework’s ASP.Net Identity provider has been replaced with:

install-package MyCouch.AspNet.Identity

To create the necessary views (secondary indexes), the user associated with the MyCouchClient that creates the views using the extension method Client.EnsureDesignDocsExists(), needs to have correct user-rights. It needs to be able to create views. Read more about this below.

You need a MyCouch Client. In the sample this is created in Global.asax:

public class MvcApplication : System.Web.HttpApplication
  protected async void Application_Start()

    using (var client = new MyCouchClient(CreateUri()))
      //Only needed once, and you can use a specific admin user to bootstrap this
      await client.EnsureDesignDocsExists();

  protected void Application_BeginRequest()
    HttpContext.Current.Items["MyCouchClient"] = new MyCouchClient(CreateUri());

  protected void Application_EndRequest()
    var client = HttpContext.Current.Items["MyCouchClient"] as IMyCouchClient;
    if (client != null)

  private static Uri CreateUri()
    return new MyCouchUriBuilder("http://localhost:5984")
      .SetBasicCredentials("demo", "p@ssword")

The EnsureDesignDocsExists method is only needed to be called once for the application lifecycle. When the views has been created this call is redundant. And since it needs higher user-rights, this could be done while bootstraping or seeding the application.

The Sample application in the repo was created with Entity framework as storage for the ASP.Net Identity models. In the AccountController, a MyCouchUserStore is instead injected into the ASP.Net Identity UserManager:

public class AccountController : Controller
  public AccountController()
    var client = (IMyCouchClient)System.Web.HttpContext.Current.Items["MyCouchClient"];
    UserManager = new UserManager(new MyCouchUserStore(client));


That’s it! To enable e.g. Google Auth. Just go to the Startup.Auth.cs file under App_Start, and uncomment:


To make use of roles, you can make use of the UserManager. A manual seed or creation would look something like this:

var mgr = new UserManager(new MyCouchUserStore(Client));
var usr = new ApplicationUser { UserName = "danieltest1" };
await mgr.CreateAsync(usr, "p@ssword");
await mgr.AddToRoleAsync(usr.Id, "Testers");

That’s it. Remember. It’s a pre v1.0.0 product.

If you want to know more about ASP.Net Identity, I’ve put together some few links below. It will be extended as I find more nice resources.



ASP.Net MVC & WebAPI, CouchDB & Cloudant, Data storage, Development
, , , , ,

Join the conversation! 5 Comments

  1. […] Using MyCouch to store ASP.NET identity data in CouchDB or in the cloud using Cloudant – An introduction to the ASP.NET Identity provider for CouchDB and Cloudant created by Daniel Wertheim. For more information have a look in the GitHub section at the end of this article. […]

  2. How to do the same in webforms?. Is there any advantages in using couchdb and What is the acutal purpose of MyCouch.AspNet.Identity. Why should I prefer it over normal sql server engine?

  3. Can I use the MyCouch.AspNet.Identity as an alternative to sql membership. Or is just another oath implmentation?

  4. Can I achieve the same result when using webforms?. Could you provide a working sample in webforms?

    • – Do not know about webforms and the Identity model. Check the link to the ASP.Net site for info.

      – The purpose is to allow you to store the identity data in CouchDb or Cloudant

      – Advantages of CouchDb over SQL server? Well, e.g. you have CouchDb and its FREE and you don’t have SQL server which is NOT FREE. You have a more flexible (per entity) model in Couch. It’s like NoSQL vs RDBMS. Lots of stuff about it out there.

      – Check the links provided and you can check up more about the new identity model (replaces membership model etc) that is used.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: