无法生成一致的令牌 ASP.NET C# 服务器端 Oauth 2.0

Cannot generate a consistant token ASP.NET C# server-side Oauth2.0

我在尝试自动生成所有客户端用户都可以使用的令牌时遇到了问题。我正在使用 Oauth 2.0。

我可以使用帐户控制器 /api/Account/Register 完美地生成令牌本地主机,但是当我发布网络时 api 我无法使用该令牌访问,而且我也无法生成令牌我做了本地主机。

有什么方法可以像我在 localhost 一样在服务器端生成令牌吗?它应该与我重新发布应用程序时令牌应该仍然相同的方式保持一致。

我正在使用 Postman 进行测试。当我用 json 调用 /api/Account/Register 时:

{
  "Email": "da@a.com",
  "Password": "sample striAng 21|",
  "ConfirmPassword": "sample striAng 21|"
}

它 returns 我是这样的错误:

{
    "Message": "An error has occurred."
}

我正在完全复制我在本地主机上所做的,但在服务器上不起作用。

看起来像是 500 内部服务器错误。 任何其他端点都在工作所有一切都不起作用?

您应该检查服务器上的连接字符串,并检查数据库是否存在以及是否有正确的表。

确保任何环境特定设置都具有有效值。

问题是您正在连接到本地计算机上的 SQL Express 数据库,但在大多数情况下,服务器不使用 SQL Express(也没有相同的凭据登录时)您必须设置 web.config 和 sql 连接。

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)"

在您的 Web.config change/comment 上输出您当前的 connectionStrings 并将其替换为您的服务器

 <connectionStrings>       
    <add name="YourDataBaseContextName" connectionString="Data Source=TheConnection;Initial Catalog=YourDataBaseName;User Id=TheUserOfDatabase;Password=YourHopeNotSoEasyPassword;" providerName="System.Data.SqlClient" />
 </connectionStrings>

What i don't understand here is why I have a sql problem, being that Account controller never uses any database?

他们确实使用它,毕竟你必须在某个地方保存寄存器数据,对吧?

更具体地说,此行将您发送的模型注册并保存到数据库中:

var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };    
IdentityResult result = await UserManager.CreateAsync(user, model.Password);