Hello,
After i published mpa project to a hosting provider, i cannot upload my profile picture due to the following error.
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.
Below is the method that abp uses to upload picture, I do not want to interfere with abp's origin code, but i think i will have to do that. How should i do that. Thanks in advance.
public JsonResult UploadProfilePicture() { try { //Check input if (Request.Files.Count <= 0 || Request.Files[0] == null) { throw new UserFriendlyException(L("ProfilePicture_Change_Error")); }
var file = Request.Files[0];
if (file.ContentLength > 5242880) //1MB.
{
throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
}
//Check file type & format
var fileImage = Image.FromStream(file.InputStream);
if (!fileImage.RawFormat.Equals(ImageFormat.Jpeg) && !fileImage.RawFormat.Equals(ImageFormat.Png))
{
throw new ApplicationException("Uploaded file is not an accepted image file !");
}
//Delete old temp profile pictures
AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());
//Save new picture
var fileInfo = new FileInfo(file.FileName);
var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
file.SaveAs(tempFilePath);
using (var bmpImage = new Bitmap(tempFilePath))
{
return Json(new MvcAjaxResponse(new { fileName = tempFileName, width = bmpImage.Width, height = bmpImage.Height }));
}
}
catch (UserFriendlyException ex)
{
return Json(new MvcAjaxResponse(new ErrorInfo(ex.Message)));
}
}
1 Answer(s)
-
0
Hi,
just add JsonRequestBehavior.AllowGet to return json values,
return Json(new MvcAjaxResponse(new ErrorInfo(ex.Message)),JsonRequestBehavior.AllowGet);
return Json(new MvcAjaxResponse(new { fileName = tempFileName, width = bmpImage.Width, height = bmpImage.Height }),JsonRequestBehavior.AllowGet);