1
我試圖資料圖片添加到我的項目,我下面這篇文章 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");
}
}
https://stackoverflow.com/questions/類的Microsoft.aspnet.identity.owin NuGet包23881489/how-to-get-applicationdbcontext -out-of-owin-pipeline我需要添加一個使用語句,但我已經做了,根據intellisense,這是不必要的 –
錯誤是在讀取var bdUsers = 。HttpContext.GetOwinContext()獲取(); –