Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make ASP.NET Identity Store User Data In Mongo (Hosted On Heroku)

Im currently working on an ASP.Net web app that uses Mongo as its backend. I have seen others try this and have changed my connection string in my Web.config to point to my Mongo instance on Heroku. My connection string format is as follows:

mongodb://username:[email protected]:port/database

The controllers and models built after creating a new ASP.Net MVC project with individual accounts selected have not been edited. I am unable to create new accounts or login with accounts I create through Mongo. I also received the following error:

Format of the initialization string does not conform to specification starting at index 0.

My research showed that this is typically due to a malformed connection string. I have double and triple checked my Mongo connection string but it looks right. Am I missing something?

Any help is appreciated!

---------------------------------------------

EDIT

I noticed that I had the providerName="System.Data.SqlClient" in the connection string. Removing this yields a different error:

The connection string 'DefaultConnection' in the application's configuration file does not contain the required providerName attribute.

like image 467
CodePull Avatar asked Dec 24 '22 15:12

CodePull


2 Answers

If you're looking for MongoDB identity store adapters supporting netstandard2.0 or netcoreapp2.0, I've recently released a MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.

It allows you to use MongoDb instead of SQL server with Microsoft.AspNetCore.Identity 2.0:

https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore

I have implemented the RoleStore and UserStore.

Fully covered by integration tests and unit tests from the modified Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test test suite.

Hope this helps.

like image 72
Darxtar Avatar answered Dec 26 '22 04:12

Darxtar


Default Asp.Net identity storage provider is working with Entity Framework that is geared for working with relational databases. MongoDB is a document database and just changing connection string will not work. You need to use different storage provider that can work with MongoDB.

A quick search reveals that there are few storage providers that work with MongoDB:

  • https://github.com/maxiomtech/MongoDB.AspNet.Identity
  • https://github.com/g0t4/aspnet-identity-mongo
  • https://github.com/steentottrup/AspNet.Identity.MongoDB

I've not tried any of them personally, but first one seems to be quite popular on GitHub.

like image 29
trailmax Avatar answered Dec 26 '22 04:12

trailmax