简体   繁体   English

使用不同的连接字符串时,C#MVC4无法使用Google登录

[英]C# MVC4 Cannot login with google when using different connection string

I have a weird problem with external google authentication. 我对外部Google身份验证有一个奇怪的问题。 Basically I'm using almost the same code which is generated by default MVC4 internet application. 基本上,我使用的是几乎与默认MVC4 Internet应用程序生成的代码相同的代码。 Everything works fine on my local machine. 在我的本地计算机上一切正常。 I can login with google account. 我可以使用Google帐户登录。

But when I change the connectrion string to external database on the web, this code: 但是,当我将connectrion字符串更改为Web上的外部数据库时,此代码:

OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false)

returns FALSE so it's not logging in, and I don't know any reason why. 返回FALSE,所以它没有登录,我也不知道为什么。 The same happens when I publish whole website on the web (with the same extenral connection string which seems to generate the problem on my local machine). 当我在Web上发布整个网站时,会发生相同的情况(使用相同的外部连接字符串,这似乎在本地计算机上产生了问题)。

The ONLY difference between working and not working version is different connection string in web.config. 工作版本和不工作版本之间唯一的区别是web.config中的连接字符串不同。

Did anyone suffer the same problem? 有人遇到过同样的问题吗?

EDIT 编辑

I didn't mention. 我没提。 The other connection string works correctly. 另一个连接字符串正常工作。 It gets all the data from database, but somehow google authentication silently fails. 它从数据库中获取所有数据,但是Google身份验证以某种方式静默失败。 It just does not log in. Database schema and the data is identical to my local database (I have even generated sql script with data and applied in on external database) Also the user which I want to log in is in this external database. 它只是不登录。数据库架构和数据与我的本地数据库相同(我什至用数据生成了sql脚本并应用于外部数据库)。我要登录的用户也在此外部数据库中。

So what is happening: OAuthWebSecurity.Login returns false so I automatically want to register new user, but then the user is found already in database and I'm getting something like "the user already exists in database". 所以发生了什么:OAuthWebSecurity.Login返回false,所以我自动希望注册新用户,但是随后该用户已经在数据库中找到,并且我得到类似“该用户已存在于数据库中”的信息。

Very weird. 很奇怪。

Did you create the user in external DB with CreateOrUpdateAccount method? 您是否使用CreateOrUpdateAccount方法在外部数据库中创建了用户? Probably you do not have associated any user with the Google credentials which you are using... 可能您没有将任何用户与您正在使用的Google凭据相关联...

The login process works in following steps: 登录过程按以下步骤进行:

  1. Hey Google, tell me who is logged in. 嗨,谷歌,告诉我谁登录了。
  2. Google tells you some UserId X Google告诉您一些UserId X
  3. OAuthWebSecurity asks your membership provider for user with GoogleUserId X OAuthWebSecurity向您的成员资格提供者询问具有GoogleUserId X的用户
  4. If there exists such a user, it logs him in and if not, login fails... 如果存在这样的用户,则将其登录,如果没有,登录失败...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM