Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将Identity PK更改为int后:从物化的';System.Int32';键入';System.String';类型无效_Asp.net_Asp.net Identity - Fatal编程技术网

Asp.net 将Identity PK更改为int后:从物化的';System.Int32';键入';System.String';类型无效

Asp.net 将Identity PK更改为int后:从物化的';System.Int32';键入';System.String';类型无效,asp.net,asp.net-identity,Asp.net,Asp.net Identity,使用Identity 2的ASP.NET网站web表单应用程序(VS 2015)。使用标准模板生成的站点(都使用字符串Id),按照教程将Users表的主键更改为Int,这就是问题开始的地方。似乎EF正在登录时检索记录,但无法填充ApplicationUser对象 如果需要的话,可以直接在SQL中编辑用户表(而不是先编码)。尝试用Id(Int)重写IdentityUser的Id(string)属性,但编译器拒绝使用不同的返回类型。建议 Line 26: **Dim user As Ap

使用Identity 2的ASP.NET网站web表单应用程序(VS 2015)。使用标准模板生成的站点(都使用字符串Id),按照教程将Users表的主键更改为Int,这就是问题开始的地方。似乎EF正在登录时检索记录,但无法填充ApplicationUser对象

如果需要的话,可以直接在SQL中编辑用户表(而不是先编码)。尝试用Id(Int)重写IdentityUser的Id(string)属性,但编译器拒绝使用不同的返回类型。建议

Line 26:       **Dim user As ApplicationUser = manager.Find(Email.Text, Password.Text)**
Line 27:       If user IsNot Nothing Then
错误跟踪:

[InvalidOperationException: The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid.]
   System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +235
   lambda_method(Closure , Shaper ) +164
   System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +181
   System.Data.Entity.Core.Common.Internal.Materialization.<MoveNextAsync>d__4.MoveNext() +374
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Data.Entity.Internal.<FirstMoveNextAsync>d__0.MoveNext() +513
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Data.Entity.Infrastructure.<FirstOrDefaultAsync>d__25`1.MoveNext() +350
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +59
   Microsoft.AspNet.Identity.EntityFramework.<GetUserAggregateAsync>d__68.MoveNext() +346
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +59
   Microsoft.AspNet.Identity.<FindAsync>d__12.MoveNext() +272
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 func) +281
   Microsoft.AspNet.Identity.UserManagerExtensions.Find(UserManager`2 manager, String userName, String password) +168
   Account_Login.LogIn(Object sender, EventArgs e) in C:\Users\Lauren\Documents\Visual Studio 2015\WebSites\Template\Account\Login.aspx.vb:26
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +109
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3449
[InvalidOperationException:从物化的'System.Int32'类型到'System.String'类型的指定强制转换无效。]
System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader,Int32序号)+235
lambda_法(闭包、整形器)+164
System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper-Shaper)+181
System.Data.Entity.Core.Common.Internal.Materialization.d_u4.MoveNext()+374
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+92
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+58
System.Data.Entity.Internal.d_u0.MoveNext()+513
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+92
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+58
System.Data.Entity.Infrastructure.d_u25`1.MoveNext()+350
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+92
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+58
Microsoft.AspNet.Identity.CultureaWater`1.GetResult()+59
Microsoft.AspNet.Identity.EntityFramework.d_u68.MoveNext()+346
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+92
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+58
Microsoft.AspNet.Identity.CultureaWater`1.GetResult()+59
Microsoft.AspNet.Identity.d_u12.MoveNext()+272
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+92
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+58
Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 Func)+281
Microsoft.AspNet.Identity.UserManager.Find(UserManager`2管理器,字符串用户名,字符串密码)+168
C:\Users\Lauren\Documents\Visual Studio 2015\WebSites\Template\Account\Login.aspx.vb:26中的Account\u Login.Login(对象发送者,事件参数e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e)+109
System.Web.UI.WebControl.Button.RaisePostBackEvent(String eventArgument)+108
System.Web.UI.WebControl.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)+10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+31
System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+3449

版本信息:Microsoft.NET Framework版本:4.0.30319;ASP.NET版本:4.6.57.0

我在
UserManager.AddRole(userId,roleId)
期间遇到此问题。有什么线索可以解决这个问题吗?我找到了答案,看看这个: