I'm developing an MVC 5 app which authenticates users with a Facebook Login. The Login functionality was working using SQL Server. I'm migrating the data collection to a local mySQL database.
I've been following the instructions on these two pages: Implementing a custom MySQL Identity Storage Provider EF6 Support
The login section is working but I'm encountering the above error in a view:
@if (Request.IsAuthenticated && User.IsInRole(MyConstants.Defaults.Roles.Admin))
Below is my constructor:
public class ApplicationDbContext : MySQLDatabase
{
public ApplicationDbContext(string connectionName)
: base("DefaultConnection")
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext("DefaultConnection");
}
}
My default connection string includes a username and password. Is there somewhere else I need to provide a reference to it?
Update 31/08
Below is the stack trace from the error. Apart from the call to System.Web.Security.RolePrincipal, the execution jumps straight into the mysql Provider. I think the code is bypassing the custom identity provider I set up - which works if I call it explicitly in the code?
[MySqlException (0x80004005): Access denied for user ''@'DevMachine' (using password: NO)]
MySql.Data.MySqlClient.MySqlStream.ReadPacket() +309
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() +39
[MySqlException (0x80004005): Authentication to host '' for user '' using method
'mysql_native_password' failed with message: Access denied for user
''@'DevMachine' (using password: NO)]
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.
AuthenticationFailed(Exception ex) +179
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() +64
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (Boolean reset) +381
MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset) +71
MySql.Data.MySqlClient.NativeDriver.Open() +831
MySql.Data.MySqlClient.Driver.Open() +22
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +239
MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() +11
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +288
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +93
MySql.Data.MySqlClient.MySqlPool.GetConnection() +65
MySql.Data.MySqlClient.MySqlConnection.Open() +641
MySql.Web.Security.MySQLRoleProvider.GetRolesForUser(String username) +63
System.Web.Security.RolePrincipal.IsInRole(String role) +199
ASP._Page_Views_Shared__Menu_cshtml.Execute() in C:\Code\Studio-NI\Studio-NI\Views\Shared\_Menu.cshtml:23