[英]ModelState Validation Error when get value from User.Identity.GetUserId()
在我的WebApi控制器发布函数中,我通过User.identity.GetUserId()
将用户ID分配给发布的对象,但是ModelState.isValid
总是返回验证错误,即
用户ID为必填项
而将值分配给必需的属性。 因此,我从userId
属性中删除了必需的属性。 它正在工作,但是我需要知道为什么ModelState
不知道User.Identity.GetUserId()
已经提供了用户ID。
如果您使用的是Web API 2,请使用User.identity.GetUserId()
代替
RequestContext.Principal.Identity.GetUserId()
要么
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
Request.GetOwinContext().GetUserManager<ApplicationUserManager>()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.