I'm using OAuth (Google and Microsoft) connection with my ASP.NET MVC multi tenant application. My user by default has TenantID assigned. This tenantID is stored in claims. But they can be assigned multiple tenants, and upon login can be prompted to choose respective tenant. Once that is done, I'm trying to replace the tenantid value in the claim here :
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;
}
I'm getting following exception in this line
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
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)
Not sure why is it trying to establish SQL connection here.