public async Task <ActionResult> UpdateUserPhotoAsync(string returnUrl) { if (Request.Files != null && Request.Files.Count > 0) { if (!Request.Files[0].ContentType.StartsWith("image")) { throw new Exception("content mismatch!"); } string IconMime = Request.Files[0].ContentType; System.Nullable <DateTime> LastModified = default(System.Nullable <DateTime>); if (Request.Form.AllKeys.Contains("LastModified")) { LastModified = DateTime.Parse(Request.Form["LastModified"]); } System.IO.Stream strm = Request.Files[0].InputStream; int size = Request.Files[0].ContentLength; byte[] data = new byte[size]; strm.Read(data, 0, size); if (await MembershipContext.UpdateUserPhoto(User.Identity.GetUserId(), IconMime, LastModified.Value, data)) { if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("Index", "Home")); } else { return(Redirect(returnUrl)); } } } ViewBag.ReturnUrl = returnUrl; return(View()); }