OAuthWebSecurity.CreateOrUpdateAccount生成FOREIGN KEY约束异常 [英] OAuthWebSecurity.CreateOrUpdateAccount generates FOREIGN KEY constraint exception

查看:41
本文介绍了OAuthWebSecurity.CreateOrUpdateAccount生成FOREIGN KEY约束异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去的几个小时,我一直在尝试在我的MVC 4网站中添加Facebook登录.

I've been trying for the past hours to add facebook login in my MVC 4 Website.

到目前为止,本地帐户注册"(WebSecurity.CreateAccount()可以正常工作.

So far the 'local account registering' ( WebSecurity.CreateAccount() works perfectly.

在我的业务逻辑中,我的代码如下:

In my businesslogic, my code looks like this:

public ValidationReturn<User> AddUser(User data, string provider, string providerUserId)
{
....

Repository.Insert(data);
SaveChanges();

OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, data.LoginName);

现在,当我尝试创建这样的帐户时,OAuthWebSecurity.CreateOrUpdateAccount会引发异常:

Right now, when I try to create a account like this, the OAuthWebSecurity.CreateOrUpdateAccount throw an exception:

INSERT语句与FOREIGN KEY约束冲突"FK_dbo.webpages_OAuthMembership_dbo.webpages_Membership_UserId".这数据库"Wims",表"dbo.webpages_Membership"中发生冲突,列"UserId".

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.webpages_OAuthMembership_dbo.webpages_Membership_UserId". The conflict occurred in database "Wims", table "dbo.webpages_Membership", column 'UserId'.

我在UserTable中看到了我的用户,并且我了解了为什么它会崩溃的数据库方案...但是我不知道原因...也是OAuthWebSecurity.CreateOrUpdateAccount也应该在webpages_Membership中创建一条记录?如果是这样,密码怎么办?

I see my user in my UserTable, and I understand looking at the db scheme why it crashes... but I do not have any idea the reason... is OAuthWebSecurity.CreateOrUpdateAccount supposed to create a record in webpages_Membership as well? if so, what about the password?

我一直在网上检查一些这样的教程: http://www.asp.net/mvc/tutorials/mvc-4/using-oauth-providers-with-mvc

I've been checking several tutorials on the web like this : http://www.asp.net/mvc/tutorials/mvc-4/using-oauth-providers-with-mvc, or http://www.asp.net/web-pages/tutorials/security/16-adding-security-and-membership and i don't see what i am missing here...

感谢您的时间.

推荐答案

好吧,我刚刚发现...我使用代码第一类,在初始化simplemembership时声明系统创建的表的结构...(因为我需要将角色放在对象中才能从网站进行管理)

Ok, i just found out... I use code first class that declare the structure of the tables created by the system when initializing the simplemembership... (because i needed to put the roles in a object to manage it from website)

示例:

   [Table("webpages_OAuthMembership")]
    public class OAuthMembership
    {
        [Key, Column(Order = 0), StringLength(30)]
        public string Provider { get; set; }

        [Key, Column(Order = 1), StringLength(100)]
        public string ProviderUserId { get; set; }

        public int UserId { get; set; }

        //[Column("UserId"), InverseProperty("OAuthMemberships")]
        //public Membership User { get; set; }
    }

一些FK错了.耶稣......

Some of the FK were wrong.. jesus....

希望它将对某人有所帮助

Hope it will help someone

这篇关于OAuthWebSecurity.CreateOrUpdateAccount生成FOREIGN KEY约束异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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