gpt4 book ai didi

MySql ASP.NET Identity 在 Win10 下意外绑定(bind)到 SQL Server

转载 作者:行者123 更新时间:2023-11-28 23:38:33 24 4
gpt4 key购买 nike

我有一个实时 Web 应用程序(ASP.NET 4.5.1、MVC 5.2.3、EF 6.1、MySql 5.1.35),它在 MS Server2008R2(Web)上运行了几个月没有任何困难。

我正在尝试将我的开发环境移动到 Win10 虚拟机(以前是 Win7 VM),并在 VS2015 中的新机器上打开实时系统和复制数据库的副本。

运行应用程序时(我使用 asp.net Identity 1.0 进行身份验证),我的 _layout.vbhtml 页面出现以下异常:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Web.dll but was not handled in user code

Additional information: 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: 26 - Error Locating Server/Instance Specified)

在:

            <div class="navbar-collapse collapse">
<ul class="nav navbar-nav" style="width:auto;white-space: nowrap;">
@If (Request.IsAuthenticated) Then
@<li>@Html.ActionLink("Home", "Index", New With {.Area = "", .controller = "Home"})</li>

If **User.IsInRole("Salesman")** Then

因为我没有使用 SQLServer,所以没有处理异常也就不足为奇了...

我很困惑为什么用户对象 (System.Web.Security.RolePrincipal) 使用 SQLClient 而不是指定的 MySQLClient:

Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("IMSSecurityEntities")
End Sub

网络配置:

  <connectionStrings>
<add name="IMSSecurityEntities" connectionString="data source=localhost;database=db1;Uid=root;Pwd=password;" providerName="mysql.data.mysqlclient" />

在 Server2008R2 机器上的 VS2015 中运行时,完全相同的项目正确连接到 MySQL 数据库。

在某些情况下,asp.net Identity 是否会“回退”到使用 SQLServer?

最佳答案

做了一些更多的挖掘和谷歌搜索,并在以下位置找到了解决方案:User.IsInRole doesn't work

将以下内容添加到 web.config 解决了问题:

<modules>
<remove name="RoleManager" />
</modules>

RoleManager 默认为 SimpleMembership。我不知道为什么这在一台机器上不是问题,但在另一台机器上却很明显,但显然某处存在歧义,这解决了它。

关于MySql ASP.NET Identity 在 Win10 下意外绑定(bind)到 SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35072568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com