我正在使用OAuth(Google和Microsoft)连接我的ASP.NET MVC多租户应用程序 . 默认情况下,我的用户已分配TenantID . 此tenantID存储在声明中 . 但是可以为他们分配多个租户,并且在登录时可以提示他们选择相应的租户 . 完成后,我试图在声明中替换声明中的tenantid值:
public static ClaimsIdentity SetTenant(int tenantID)
{
var claims = HttpContext.Current.GetOwinContext().Authentication.User.Claims;
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
if (identity.FindFirst("tenantid") != null)
{
identity.RemoveClaim(identity.FindFirst("tenantid"));
}
identity.AddClaim(new Claim("tenantid", tenantID.ToString()));
System.Web.HttpContext.Current.Items["TenantID"] = tenantID;
return identity;
}
我在这一行中遇到了异常
var identity = new ClaimsIdentity(claim,DefaultAuthenticationTypes.ApplicationCookie); Build 与SQL Server的连接时发生与网络相关或特定于实例的错误 . 服务器未找到或无法访问 . 验证实例名称是否正确,以及SQL Server是否配置为允许远程连接 . (提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)
不知道为什么要在这里 Build SQL连接 .
1 回答
这个似乎工作: