Configuring ASP.NET Identity to use MySQL - mysql

I am using Visual Studio 2013 to develop a web forms application. I selected Authentication: Individual user accounts. I want the application including ASP Identity to use MySQL.
I added references to MySql.Data, MySql.Data.Entity.EF6, MySql.Web and have made the following changes to Web.config:
<connectionStrings>
<add name="EkoPayMaster.Properties.Settings.EkoPayMasterConnectionString" connectionString="server=localhost;user id=root;persistsecurityinfo=True;database=paymaster" />
</connectionStrings>
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear />
<add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web" connectionStringName="EkoPayMasterConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" autogenerateschema="true" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add type="MySql.Web.Security.MySqlProfileProvider, MySql.Web" name="MySqlProfileProvider" applicationName="/" connectionStringName="EkoPayMasterConnectionString" autogenerateschema="true" />
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
<providers>
<clear />
<add connectionStringName="EkoPayMasterConnectionString" applicationName="/" name="MySqlRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web" autogenerateschema="true" />
</providers>
</roleManager>
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"></remove>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0" />
</DbProviderFactories>
</system.data>
When I run the application, I am able to register a user and log in. However, ASP Identity does not create the necessary user tables is the MySql database.
What do I need to do to have the application add the tables/user information into MySql?

First of all, as I know, you must use exactly the same connection string name you gave in connectionStrings/add name in all your providers' connectionStringName attributes.

Related

Entity Framework 6 with Mysql "System.InvalidOperationException"

I'm new with .net
I'm trying building console app with EF6 and MySql
i always got this error when running it
this is my app.conf
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="MyContext" providerName="MySql.Data.MySqlClient"
connectionString="server=192.168.1.212;port=3306;database=zkatt;uid=fanta;password=040506"/>
</connectionStrings>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description="MySQL Database Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
</configuration>
my context class
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public partial class Entities : DbContext
{
public Entities()
: base("name=MyContext")
{
}
anything i miss?
*edit
this is full report error
Remove the useless node :
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description="MySQL Database Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
And specify version of your MySqlClient provider like :
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
Downgrade mysql entity to 6.9.10, now its work, wasted my 6 hours.

How do i fix "Specified key was too long; max key length is 1000 bytes"

I am getting "Specified key was too long; max key length is 1000 bytes" on my server. I have the following (if i miss off a tag its just poor copy and paste.
<configuration>
<configSections>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxxx" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ArticleContext" providerName="MySql.Data.MySqlClient" connectionString="server=xxxxxxxx; Port=xxxx; database=xxxxxx; User Id=xxxxxx; Pwd=xxxxx" />
</connectionStrings>
<system.web>
<httpRuntime targetFramework="4.5" />
</system.web>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
and further down
<entityFramework>
<contexts>
<context type="EverythingASP.DAL.ArticleContext, EverythingASP">
<databaseInitializer type="EverythingASP.DAL.Initializer, EverythingASP" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Any ideas what to look for? I dont even know what key it's referring to. When googling the only answers were with regards to migrations, and I don't have any in this as far as I'm aware.
Update #1
All entities have Ids assigned automatically by EF when they are created. This error is persisting on startup! The ids are all defined for the entities I have as:
[Key]
public int Id { get; set; }
So at run-time the max key value is 28...
Is this an issue with EF6 and mysql ?
The answer was to change the storage engine from myisam to innodb. This can be done in script, or if you are using godaddy, go on each of the tables and theres a button in the columns. dont ring support, they dont even know what it is.

Enity Framework With MySQL

I am getting the following error
"The Entity Framework provider type 'MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity' registered in the application config file for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."
However I do have MySql.Data.dll and MySql.Data.Entity.dll and also MySql.Data.Entity.EF6.dll referenced in my project (comes from MySQL Connector Net 6.8.3)
Here is my App.conf
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="inspectm_inspectContext" connectionString="server=--user id=--;password=--;database=--;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
</providers>
</entityFramework>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="inspectm_inspectContext" connectionString="server=--;user id=--;password=--;database=--;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
</configuration>
My Complete App.conf this worked for me
First I removed
<DbProviderFactories>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
Then I changed
<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
And Added the provider
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
for anyone facing the same problem, here is the line that causes the Exception is this
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
Just append .EF6 to MySql.Data.Entity such that the provider is like this
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
As such your choice to remove the code within didn't help solve the problem. I hope this helps someone.
Check for an inner exception.
I get
{"Inheritance security rules violated by type:
'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either
match the security accessibility of the base type or be less
accessible.":"MySql.Data.Entity.MySqlEFConfiguration"}
That points me to:
Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'
I dont really like to downgrade. But so far i haven't found a better answer.
You could also do this:
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
{

having trouble on using ext.net with razor

i am new to ext.net framework.
I am trying to use the ext.net frame work along with razor to develop an web application using MVC4.
Ext.net being an open source technology i downloaded it and tried to run it .
I am having lots of trouble using this technology.
i configured my web config file according to the given instruction and added reference to the project such as ext.net, transformer.net, newtonsoft.json..
But as i start to use the code
#Html.X().ResourceManager(),
it doesnot allow me to use the .X() part creating the problem.
This implies that the ext.net framework has not been properly installed in my system but i have done all the neccesary steps.
so guys help me out. and i could not find many tutorials regarding this technology except on http://mvc.ext.net
any help on this matter would be very helpful and any one who would like to guide me is mostly welcomed
Try to install the Microsoft ASP.NET MVC package
(use Nu-get console Manager) and you can install Ext.NET with this command
Install-Package Ext.NET.MVC
If you have a Web.config file inside your /Views/ folder, please ensure the Ext.NET required nodes are also added to that Web.config file.
I think there is a problem with your web.config files.
Here my MVC 4 ext.net integrated application web.config file.
I hope it helps.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false"/>
</configSections>
<extnet theme="Gray"/>
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MVC4ExtNetTemplate-20130401120654;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MVC4ExtNetTemplate-20130401120654.mdf" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Ext.Net"/>
<add namespace="Ext.Net.MVC"/>
</namespaces>
</pages>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<!--
If you are deploying to a cloud environment that has multiple web server instances,
you should change session state mode from "InProc" to "Custom". In addition,
change the connection string named "DefaultConnection" to connect to an instance
of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
-->
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
<httpHandlers>
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false"/>
</httpHandlers>
<httpModules>
<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net"/>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net"/>
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>

asp.net mvc2 login failed with mysql

i am using asp.net mvc2 with mysql db. i add mysql membership provider,profileprovider,role provider for mysql.the i use asp.netconfiguration tool to create roles.it works and create roles.then i try to login at that time it shows The user name or password provided is incorrect.when i create role defaul mysql membership,role tables are created in the database.
my wb config provider initialization part is as follows.
<membership defaultProvider="MySQLMembershipProvider">
<providers>
<clear />
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.5, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ApplicationServices" applicationName="MYAPP" writeExceptionsToEventLog="False" autogenerateschema="True" enablePasswordRetrieval="False" enablePasswordReset="True" requiresQuestionAndAnswer="False" requiresUniqueEmail="False" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
<profile defaultProvider="MySQLProfileProvider">
<providers>
<clear />
<add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.5, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ApplicationServices" autogenerateschema="true" />
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySQLRoleProvider">
<providers>
<clear />
<add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.3.5, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ApplicationServices" autogenerateschema="true"/>
</providers>
</roleManager>
any one know why it doent allow to login.
I know its the obvious - but have you gone into the new db and ensured the login information and password are indeed correct?
You mentioned you created the roles - but no mention of creating the users, which you would need to do in the aspnet tool as well.