没有给定的参数对应于 'IOwinContext.Get<T>(string)' 的所需形式参数 'key'
There is no argument given that corresponds to the required formal parameter 'key' of 'IOwinContext.Get<T>(string)'
我正在尝试向我的项目添加个人资料图片并且我正在关注这篇文章
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
命名空间。它具有 class,其中包含您正在寻找的 Get
方法。
我正在尝试向我的项目添加个人资料图片并且我正在关注这篇文章 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
命名空间。它具有 class,其中包含您正在寻找的 Get
方法。