Search code examples
asp.net-mvcowin

There is no argument given that corresponds to the required formal parameter 'key' of 'IOwinContext.Get<T>(string)'


I am trying to add a profile picture to my project and I am following this article https://social.technet.microsoft.com/wiki/contents/articles/34445.mvc-asp-net-identity-customizing-for-adding-profile-image.aspx#Step_4_IdentityModels_cs and in the article there is a part where I have to get the user details to load the user's image. At this step I get the error in the heading, what am I missing?

    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");             
        }

    }

Solution

  • You have to reference the Microsoft.AspNet.Identity.Owin namespace. It has the class that has the Get method you are looking for.