没有给定参数对应于“IOwinContext.Get (串)”
问题描述:
我试图资料图片添加到我的项目,我下面这篇文章 https://social.technet.microsoft.com/wiki/contents/articles/34445.mvc-asp-net-identity-customizing-for-adding-profile-image.aspx#Step_4_IdentityModels_cs 并在需要的形式参数的“钥匙”文章中有一部分我必须获取用户的详细信息来加载用户的图像。在这一步我在标题中得到错误,我错过了什么?没有给定参数对应于“IOwinContext.Get <T>(串)”
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");
}
}
答
你要引用有具有get方法,你根据这个找
https://*.com/questions/类的Microsoft.aspnet.identity.owin NuGet包23881489/how-to-get-applicationdbcontext -out-of-owin-pipeline我需要添加一个使用语句,但我已经做了,根据intellisense,这是不必要的 –
错误是在读取var bdUsers = 。HttpContext.GetOwinContext()获取(); –