Usermanager发现异步错误

问题描述 投票:0回答:2

我正在尝试使用Oauth令牌在.net api上进行身份验证,当我访问/ auth路由时出现以下错误:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:50 - 发生本地数据库运行时错误。指定的LocalDB实例不存在。

我整天试图解决这个问题,但没有成功。如果我得到一些帮助,我会很高兴的。

所以,这是我得到错误的代码:

   var allowedOrigin = "*";

        context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

        var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
        AspnetUserService service = new AspnetUserService();


        ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password); <---- here, when i send via Postman, i'll wait ~2 minutes to get a response. When the response arrived, this above error appears.

奇怪的是,我试图在DB上进行新的注册,并且有效。我试图从DB获得一些值,也工作。

我在本地运行SQL服务器,这些是我的两个连接字符串:

<add name="AuthContext" connectionString="Server=localhost;Initial Catalog=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />
<add name="SeeMe2Entities" connectionString="metadata=res://*/Context.SeeMe.csdl|res://*/Context.SeeMe.ssdl|res://*/Context.SeeMe.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=SeeMe2;persist security info=True;user id=SeeMe2;password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

我试图调试代码,所有变量似乎都有正确的值。有什么建议?非常感谢 !

c# sql asp.net-identity
2个回答
1
投票

您的SQL连接字符串有问题。

您的连接字符串是:

<add name="AuthContext" connectionString="localhost;Initial Catalog=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />

那里没有服务器和数据库属性。

正确的连接字符串是:

<add name="AuthContext" connectionString="Server=localhost;Database=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />

有关连接字符串的更多信息是here

另请检查您的SeeMe2Entities连接字符串。

我可以看到它在连接部分的值不正确(您也错过了服务器和数据库)。


0
投票

在AuthContext连接字符串Server属性丢失。它应该是这样的。

<add name="AuthContext" connectionString="Server=localhost;Initial Catalog=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />
© www.soinside.com 2019 - 2024. All rights reserved.