I have a custom membership provider that I've specified to be used in my web.config file for an MVC3 project. I assumed that it would be used in place of the built in membership provider since I'm specifying its use like so:
<system.web>
<membership defaultProvider="CustomMySQLMembershipProvider">
<providers>
<clear />
<add
connectionStringName="dbConn"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="25"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/jp2012"
name="CustomMySQLMembershipProvider"
type="NameSpace.CustomMySqlMembershipProvider" />
</providers>
</membership>
</system.web>
Do I have to do something in my code to get it to override the default membership provider? Right now I can access it like this:
CustomMySqlMembershipProvider membership =
(CustomMySqlMembershipProvider)Membership.Providers["CustomMySQLMembershipProvider"];
Is there a way that I can get it to be automagically overriden using the web.config file so I don't have to hardcode my implementations name? Something more like this:
MembershipProvider membership = new MembershipProvider();
Any ideas? Let me know if you need more information.
Your Membership provider is the default provider in your case. You don't need to explicitly cast the provider unless you have additional functionality in your provider.
For example when you call Membership.GetUser() it will call your membership prover's GetUser(...) method.
The issue was actually with how I declared my membership. The line
type="NameSpace.CustomMySqlMembershipProvider"
did not specify the assembly that my custom membership provider was defined in. I right clicked on my project, selected properties, and got the assembly name from the field marked Assembly name.
So if my assembly name was AName, then this line should have been
type="NameSpace.CustomMySqlMembershipProvider, AName"
Thank you #Eranga for attempting to help me out.
Related
Ok, there already is a similar issue. It is, however not exactly the same and the solution I got was not derived from the other issue's solution.
Here's my Web.Config setup:
<connectionStrings>
<add name="ADOEntities" connectionString="metadata=res://*/ADOModel.csdl|res://*/ADOModel.ssdl|res://*/ADOModel.msl;provider=Devart.Data.Oracle;provider connection string="User Id=dbUser;Password=*****;Server=oracleserver;Persist Security Info=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
Everything runs fine on my machine (sic), but when I tried to set the ws up on the quality server, I got the error on the title.
I got it working by following the steps in this ADO.NET link. Particularly,
You need to remove the defaultConnectionFactory registration and to add the Entity Framework provider registration by registering it in the entityFramework section
So the line defaultConnectionFactory must go
<entityFramework>
<providers>
<provider invariantName="Devart.Data.Oracle" type="Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity.EF6, Version=9.6.696.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</providers>
</entityFramework>
Then, add the System.Data section. In my case it looks like this:
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.Oracle" />
<add name="dotConnect for Oracle" invariant="Devart.Data.Oracle" description="Devart dotConnect for Oracle" type="Devart.Data.Oracle.OracleProviderFactory, Devart.Data.Oracle, Version=9.6.696.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>
</system.data>
If that still doesn't do the trick for you -- And it didn't for me -- try adding the following line to your context class:
[DbConfigurationType(typeof(Devart.Data.Oracle.Entity.OracleEntityProviderServicesConfiguration))] //Add this line
public partial class ADOEntities : DbContext
You might want to create a partial class, incase you're using ADO, Devart, or other auto-generated entity model, to avoid having this piece of code in an auto-generated class
I have just migrated to EF6 and here is what is happening.
I have done everything suggested in any post on stackoverflow or oracle so I decided to open another question.
1) My Model is in a separated assembly.
2) I have done everything that I was supposed to do to regenerate my Model (deleted the .tt files and refresh my model from DB).
3) After doing that, the new EF seems to be too smart and decided to create all my number(1) fields as boolean.
4) this would cause an enormous rework for me.
5) I decided to added the following entries to web.config in the solution where I have the Model.
<oracle.dataaccess.client>
<settings>
<add name="int16" value="edmmapping number(1,0)" />
<add name="int16" value="edmmapping number(3,0)" />
<add name="int16" value="edmmapping number(4,0)" />
<add name="int32" value="edmmapping number(9,0)" />
<add name="int64" value="edmmapping number(18,0)" />
</settings>
</oracle.dataaccess.client>
I refreshed my model and everything was fine.
6) When I run the app that has reference to my Model Assembly, i get the following exception when opening my connection to the Oracle Database.
error 2019: Member Mapping specified is not valid. The type 'Edm.Int16[Nullable=True,DefaultValue=]' of member 'TRACKATTENDANCEFLAG' in type 'Model.FACILITY' is not compatible with 'OracleEFProvider.number[Nullable=True,DefaultValue=,Precision=1,Scale=0]' of member 'TRACKATTENDANCEFLAG' in type 'Model.Store.FACILITY'.
7) I have added the same entries in the application that uses the Model but it does not matter, I keep getting the same exception.
8) I'm not using the Managed Drive. I'm using the Oracle.DataAccess.Client.
9) Oracle.DataAccess.Client version 2.121.2.0
Oracle.DataAccess.EntityFramework version 6.121.2.0
Does anyone have any ideas? I spent more than 20 hours trying to figure out. I have tried all possible combinations.
It is so freaking wrong that Oracle would let me generate my Model but failed during runtime against the exact database.
I appreciate any help
Had the same issue and tried all solutions I've found. The only one that worked was adding the following code to all my Web.config and app.config files under the <connectionStrings></connectionStrings>.
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmNumberMapping>
<add NETType="int16" MinPrecision="1" MaxPrecision="4" DBType="Number"/>
</edmNumberMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
My setup is:
EF6
Oracle ManagedDataAccess Client 4.121.2.0
I had a similar problem with the same error message. In my case I was trying to map a number(1,0) column to a boolean and I am using an EDMX file. Previously this project worked and didn't display an error message but with the latest version of oracle developer tools installed and Visual Studio 2019 it started displaying this error message. The project compiled and worked fine but adding this to the web.config removed the error messages as well.
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmMapping dataType="number">
<add name="bool" precision="1" />
</edmMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
When you have multiple membership providers configured, like:
<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />
<add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
</providers>
</membership>
Then let's say, for a particular section in the site I want to use SimpleMembershipProvider for auth (the rest of the site will use the default provider i.e. UmbracoMembershipProvider) ... Therefore I need to initialize SimpleMembership with:
WebSecurity.InitializeDatabaseConnection(
Constants.Membership.ConnectionStringName,
Constants.Membership.TableName,
Constants.Membership.UserIdColumnName,
Constants.Membership.UserNameColumnName,
false);
But it seems the above code only works when SimpleMembershipProvider is the defaultProvider. I can't see a way to specify the provider name I want to use? Is this even possible? Or does simplymembership assume you have one membership and role provider defined?
SimpleMembershipProvider is an implementation of ExtendedMembershipProvider. Although WebSecurity will work with any implementation of the extended provider it has some questionable coupling to SimpleMembershipProvider if used.
Basically SimpleMembershipProvider requires initialisation via WebSecurity, otherwise it will throw an exception when the extended membership interface is used. If not initialised then it wraps the default ASPNET provider and can be used with the original MembershipProvider Interface and old schema.
The initialisation routine only initialises the default providers, provided they can be cast to the simple provider implementations. So yes you cannot use SimpleMembershipProvider or SimpleRoleProvider unless they are configured as the default instances.
There's some more information about the limitations of SimpleMembershipProvider here.
There is a work-around. You can use reflection to temporarily swap the provider to the default during initialisation and then switch it back. See BetterMembership.Net for an example of doing exactly that. This library extends SimpleMembershipProvider specifically for use in multi-provider systems.
membershipProviderField = typeof(Membership)
.GetField("s_Provider", BindingFlags.NonPublic | BindingFlags.Static);
var originalMembershipProvider = membershipProviderField.GetValue(null);
membershipProviderField.SetValue(null, mySimpleMembershipProvider);
WebSecurity.InitializeDatabaseConnection(...)
membershipProviderField.SetValue(null, originalMembershipProvider);
I'm using the AuthorizeAttribute and the default forms authentication that comes with the "Internet Application" preset.
Everything is working as it should, but I have some questions about deployment.
I've got this in the web.config:
<connectionStrings>
<add name="AlltForMusikContext" connectionString="Data Source=|DataDirectory|AlltForMusik.sdf" providerName="System.Data.SqlServerCe.4.0"/>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
I tried to get it to use the database in "AlltForMusikContext" but with no success. When I deploy the site, I will only have one (1) SQL-database.
How does this work really? Is the "aspnetdb.mdf" some special db or do I need to get it to use the db in "AlltForMusikContext"?
I couldn't find any relevant info about this, so I would really appreciate your input!
Best regards
Mikael
you are right, your application is having default "aspnetdb.mdf" in you application under "App_Data" folder.
putting AspNetDb.mdf file under application folder is not a good practice rather than you can create a separate database with name and use that. putting your membership database along with your application database does not make good sense.
I have an ASP.NET web project and a membership provider configured via my web.config. Its fully working so no problem there.
We have an older system with a lot of users and I would therefor like to create a class library that can create users in this ASP.NET project but since its a class library it cannot have its own app.config-file.
is it possible to set all this information via code somehow?
<membership defaultProvider="ShidMembershipProvider">
<providers>
<clear/>
<add name="ShidMembershipProvider" type="SundaHus.AspNet.Membership.ShidMembershipProvider" connectionStringName="ShidConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiersQuestionAndAnswer="true" applicationName="ECB3-development" minRequiredPasswordLength="5"/>
</providers>
</membership>
You have a custom membership provider it looks like? This connects to your own custom database? You should be able to just point to that database for your code. Or, if you just inherit the functionality from the base class, you can also try overriding the Initialize method, look for the connection string, and change the value to something else.