gpt4 book ai didi

asp.net-mvc - 没有给出对应于 'key' 的必需形式参数 'IOwinContext.Get(string)' 的参数

转载 作者:行者123 更新时间:2023-12-04 02:46:40 24 4
gpt4 key购买 nike

我正在尝试向我的项目添加个人资料图片,我正在关注这篇文章
https://social.technet.microsoft.com/wiki/contents/articles/34445.mvc-asp-net-identity-customizing-for-adding-profile-image.aspx#Step_4_IdentityModels_cs
在文章中有一部分我必须获取用户详细信息才能加载用户的图像。在这一步我得到标题中的错误,我错过了什么?

    public FileContentResult UserPhoto()
{
if (User.Identity.IsAuthenticated)
{
String userId = User.Identity.GetUserId();
if (userId == null)
{
string filename =
HttpContext.Server.MapPath(@"~/Uploads/ProfilePictures/blankprofile.png");
byte[] imageData = null;
FileInfo fileInfo = new FileInfo(filename);
long imageFileLength = fileInfo.Length;
FileStream fs = new FileStream(filename, FileMode.Open,
FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imageData = br.ReadBytes((int)imageFileLength);
return File(imageData, "image/png");
}
// to get the user details to load user Image
var bdUsers =
HttpContext.GetOwinContext().Get<ApplicationDbContext>();
var userImage = bdUsers.Users.Where(x => x.Id ==
userId).FirstOrDefault();
return new FileContentResult(userImage.ProfilePicture,
"image/jpeg");
}
else
{
string fileName =HttpContext.Server.MapPath(@"~/Uploads/ProfilePictures/blankprofile.png");

byte[] imageData = null;
FileInfo fileInfo = new FileInfo(fileName);
long imageFileLength = fileInfo.Length;
FileStream fs = new FileStream(fileName, FileMode.Open,
FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imageData = br.ReadBytes((int)imageFileLength);
return File(imageData, "image/png");
}

}

最佳答案

您必须引用 Microsoft.AspNet.Identity.Owin命名空间。它的类具有 Get您正在寻找的方法。

关于asp.net-mvc - 没有给出对应于 'key' 的必需形式参数 'IOwinContext.Get<T>(string)' 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47107647/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com