我在主项目的webconfig中遇到了EF连接字符串的问题。如果我在主项目的webconfig中登录并拥有EF连接字符串,则Ef连接字符串用于标识表,
<add name="HWCIdentityEntities" connectionString="metadata=res://*/HWCIdentityEF.csdl|res://*/HWCIdentityEF.ssdl|res://*/HWCIdentityEF.msl;provider=System.Data.SqlClient;provider connection string="data source=****;initial catalog=*****;persist security info=True;user id=*****;password=****;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
我收到错误
实体类型ApplicationUser不是当前上下文模型的一部分。
并指向
Line 78: var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); in my AccountController
但是,如果我在主项目的webconfig中使用此版本的connectionstring
<add name="HWCIdentityEntities" connectionString="Data Source=****;Initial Catalog=****;User ID=****;password=****;Integrated Security=false;" providerName="System.Data.SqlClient"/>
然后我就可以登录没问题了。
我无法对我的连接字符串使用第二个选项,因为我正在运行ajax调用以获取AspNetUsers表以获取登录用户的id并将其放入javascript变量中以便我可以在整个应用程序中访问它。
这就是我在_LoginPartial
中运行ajax的方法<script>
$(document).ready(function () {
CommonMethod.GetCurrentUserID($('#loggedInUser').text().replace("Hello ", "").replace("!", ""));
});
</script>
并且GetCurrentUserID调用是
GetCurrentUserID: function (useremail) {
$.ajax({
type: "GET",
url: "../CommonMethods/GetCustomerID?useremail=" + useremail,
contentType: "application/json; charset=utf-8",
success: function (data, textStatus, jqXHR) {
HWCStorage.Keys.CurrentUserID = data;
}
});
}
并且调用
[HttpGet]
public string GetCustomerID(string useremail)
{
HDA = new HWCDA();
return HDA.CurrentUserID(useremail);
}
然后调用此
public string CurrentUserID(string useremail)
{
string userID = string.Empty;
HWCI = new HWCIdentityEntities();
userID = HWCI.AspNetUsers.Where(w => w.Email == useremail).Select(s=>s.Id).FirstOrDefault();
return userID;
}
所以简而言之,我需要知道为什么我不能在我的主项目web配置中使用EF连接字符串来识别身份