【发布时间】:2015-10-13 12:46:30
【问题描述】:
这是我的控制器动作方法-------
public HttpResponseMessage PostPost(Post post)
{
// previosly i was using simple membership to get id of logged in user
// post.PostedBy = WebSecurity.CurrentUserId;
post.PostedBy = User.Identity.GetUserId<int>();
post.PostedDate = DateTime.UtcNow;
ModelState.Remove("post.PostedBy");
ModelState.Remove("post.PostedDate");
if (ModelState.IsValid)
{
db.Posts.Add(post);
db.SaveChanges();
// now i am facing problem at this line. it is saying that
//Operator '==' cannot be applied to operands of type 'int' and 'string'
var usr = db.Users.FirstOrDefault(x => x.Id == post.PostedBy);
当我使用简单的会员资格时,我的代码工作正常。我应该尝试什么让它工作。在这里,post 是一个属性 PostedBy 为 int 的类,我想将当前的 loggedIn userId 值分配给该属性。
【问题讨论】:
-
我喜欢你在一个问题中使用了 20 次“发布”这个词,尤其是方法签名:)
-
哈哈哈我能做什么.....这只是一个我没有注意到@DavidG的代码
标签: c# asp.net-identity-2