AppHarbor MongoDB Membership Provider

I have an app on AppHarbor and I finally got it to work. One thing that eluded me made my membership provider work. I use MongoLab for my database and it works great with the rest of my application. When I try to use membership, I get this error:

Unable to connect to server localhost:27017: No connection could be made because the target machine actively refused it 127.0.0.1:27017. 

And the violation line is in the web.config file:

 <add name="MongoDBMembershipProvider" type="MongoDB.Web.Providers.MongoDBMembershipProvider".... 

Can someone shed light on my situation?

+4
source share
3 answers

As mentioned in friism, you need code to read connectionString from appSetting. Fortunately, osuritz has already done the work in the MongoDB.Web fork on github.

You will need to download the above fork, create and modify the existing dll link to use the new dll.

Then...

change the configuration:

 <appSettings> <add key="MONGOLAB_URL" value="mongodb://localhost/ASPNETDB"/> </appSettings> 

... the above value will be replaced by appharbor / mongolab (and if you have other parts of the application that work, then this is correct)

 <providers> <clear /> <add name="MongoDBMembershipProvider" type="MongoDB.Web.Providers.MongoDBMembershipProvider" applicationName="/" appSettingsConnectionStringKey="MONGOLAB_URL" collection="Users" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" /> </providers> 

So, in the above configuration, it has the appSettingsConnectionStringKey parameter. The code inside the custom provider reads the value of appSettingsConnectionStringKey "MONGOLAB_URL", and then uses it to read ConfigurationManager.AppSettings ["MONGOLAB_URL"], and it obviously MUST match the specified add key name.

+4
source

In <membership defaultProvider="MongoMember"><providers><add connectionStringName="foo"> you probably need to specify the name of the connecting string that has the MongoLab connection. Unfortunately, this is not inserted into the connectionstrings element, it is in appSettings. You should probably figure out how to get the provider to read the connection string from appSettings.

+1
source

Suggests using this project for your purpose http://extmongomembership.codeplex.com/ . It supports the use of AppHarbor out of the box.

You just need to add useAppHarbor = "true" to the provider settings, as it is written here https://extmongomembership.codeplex.com/wikipage?title=AppHarbor%20Integration&referringTitle=Documentation

Note. This is the port of the new membership provider that was introduced in ASP.NET MVC4

0
source

Source: https://habr.com/ru/post/1403250/


All Articles