在MySQL中读取asp.net成员表时出错 [英] error when reading asp.net membership tables in MySQL

查看:168
本文介绍了在MySQL中读取asp.net成员表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用mysql作为成员的asp.net网站.当我连接到Windows OS上托管的mysql时,Web应用程序运行良好,但是由于Linux上的表名(区分大小写)而引发错误.

I have an asp.net website that uses mysql for membership. the web app works well when i am connecting to mysql hosted on windows OS but throws an error due to table name (case-sensitivity) on Linux.

该错误与我的表无关,但与调用身份验证用户时与内部MySQL适配器类有关.

The error is not relavant to my tables, but it is related to internal MySQL adapter classes when calling to authenticate a user.

这是错误:

表' dbname.AspNetUsers'不存在

描述:在执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:MySql.Data.MySqlClient.MySqlException:表'dbname.AspNetUsers'不存在

Exception Details: MySql.Data.MySqlClient.MySqlException: Table 'dbname.AspNetUsers' doesn't exist

鉴于,我的数据库中有小写的aspnetusers表.仅当我将主机从Windows上的mySQL更改为Linux时,才会出现该错误.

Given, i have aspnetusers table with lower case in my database. the error raises only when i change the host from mySQL on windows to Linux.

这是引发异常的代码行:

Here is the line of code that throws the exception:

public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
        {
            return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
        }

还请注意,由于我使用的是(成员资格,角色提供者)配置来连接和验证用户,因此asp.net Web应用程序中没有任何成员资格表.

Also note, i don't have any membership tables in the asp.net web app since i am using the configs for (membership, role provider) to connect and authenticate users.

感谢任何帮助.

推荐答案

我发现您可以通过覆盖 IdentityModels .cs.

I found that you can re-map table names for identity and membership provider in asp.net by overriding the OnModelCreation method in IdentityModels.cs.

这是解决方案:

    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);

                modelBuilder.Entity<ApplicationUser>().ToTable("aspnetusers");
                modelBuilder.Entity<IdentityRole>().ToTable("aspnetroles");
                modelBuilder.Entity<IdentityUserRole>().ToTable("aspnetuserroles");
                modelBuilder.Entity<IdentityUserClaim>().ToTable("aspnetuserclaims");
                modelBuilder.Entity<IdentityUserLogin>().ToTable("aspnetuserlogins");

}

您注意到,显式将所有标准asp.net成员资格表名称设置为小写,因为我在导致问题的数据库中将其设置为小写.

You notice that explicitly set all standard asp.net membership table names to lower case as i have it in my database which was causing the issue.

现在,我可以从连接到基于Linux的MySQL DB的现有Web应用程序中连接,认证和管理成员身份.

Now i can connect, authenticate and manage membership from my existing web app that is connected to Linux based MySQL DB.

希望这会有所帮助.

这篇关于在MySQL中读取asp.net成员表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆