public ServiceResponce Write(Guid senderID, Guid reciverID, string body)
{
Message message = new Message
{
Body = body
};
var reciver = context.Users.Where(c => c.Id == reciverID).Single();
var sender = context.Users.Where(c => c.Id == senderID).Single();
message.Sender = sender;
message.Reciver = reciver;
context.SaveChanges();
return new ServiceResponce();
}
我得到了空序列的异常。我从HTTPContext.Users.FindFirstValue(ClaimTypes.NameIdentifier)
得到了Guid id结果,但得到的结果不是null。我无法解决此问题。
调用方方法:
public IActionResult Wright(Guid reciverID,string body)
{
var userID = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
var neededID = Guid.Parse(userID);
_chatService.Write(neededID, reciverID, body);
return Ok();
}
1条答案
按热度按时间vmdwslir1#
试试这个: