Access denied for user ''@'(DevMachine)' (using password: NO) MVC5 Identity MySQL

0

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
mysql
asp.net-mvc-5
asp.net-identity
asked on Stack Overflow Aug 29, 2016 by Spodgy • edited Aug 31, 2016 by Spodgy

1 Answer

1

I tried another mySQL Identity example with a pre-built MySQL Identity provider in Nuget - Adding the User.IsInRole clause in the view didn't bomb the application, but the answer was always coming back false, regardless of the roles the user was a member of.

In another SO question relating to this issue the following solution was suggested: https://stackoverflow.com/a/31325939/530762

In the Web.Config I already had remove FormsAuthenticationManager but adding this line did the trick:

<modules>
    <remove name="RoleManager" />
</modules>
answered on Stack Overflow Sep 3, 2016 by Spodgy • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0