I has a one API Solution(Target Framework 4.0) and one MVC Solution(Target Framework 4.5.1) of job portal. In profile summery I need to upload a video but the problem I faced , I can not upload a video file which size is greater than 2MB. So, I search on internet and find a solution is that change the web.config on Api Solutions with this as mension below,
Web.config
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime executionTimeout="108000" maxRequestLength="2147483647"/>
</system.web>
<system.webServer>
<!-- maxAllowedContentLength = 2GB (the value is in Bytes) -->
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
after apply this same problem occurred "Failed!The remote server returned an error: (500) Internal Server Error."
Here my Controller Code on MVC solutions CandidateController
#region UPDATE CANDIDATE PROFILE SUMMERY
[HttpPost]
public string UpdateProfileSummery(string info)
{
string Res = "";
string Token = "";string FileName="";
ResultInfo<string> ResultInfo = new Models.ResultInfo<string>();
CandidateProfileSummery ProfInfo = new CandidateProfileSummery();
try
{
if (info != "" && info != null)
{
ProfInfo = JsonConvert.DeserializeObject<CandidateProfileSummery>(info);
//ProfInfo.Gender = ProfInfo.NamePrefix == "Mr." ? "male" : "female";
if (Request.Files.Count > 0)
{
// Get all files from Request object
HttpFileCollectionBase files = Request.Files;
if (User.Identity.Name != "" && User.Identity.Name != null)
{
string[] arr = User.Identity.Name.Split('|');
Token = arr[0];
ProfInfo.ID = Convert.ToInt64(arr[3]);
}
for (int i = 0; i < files.Count; i++)
{
HttpPostedFileBase file = files[i];
int fileSizeInBytes = file.ContentLength;
FileName = file.FileName;
if (file.FileName.ToLower().Contains(".mp4")|| file.FileName.ToLower().Contains(".mov") || file.FileName.ToLower().Contains(".wmv") || file.FileName.ToLower().Contains(".avi") || file.FileName.ToLower().Contains(".flv") || file.FileName.ToLower().Contains(".mkv") || file.FileName.ToLower().Contains(".3gp"))
{
ProfInfo.VideoType = Path.GetExtension(file.FileName);
if (ProfInfo.VideoType != ".mp4" && ProfInfo.VideoType != ".MP4" && ProfInfo.VideoType != ".MOV" && ProfInfo.VideoType != ".mov" && ProfInfo.VideoType != ".WAV" && ProfInfo.VideoType != ".wmv" && ProfInfo.VideoType != ".AVI" && ProfInfo.VideoType != ".avi" && ProfInfo.VideoType != ".FLV" && ProfInfo.VideoType != ".flv" && ProfInfo.VideoType != ".MKV" && ProfInfo.VideoType != ".mkv" && ProfInfo.VideoType != ".3GP" && ProfInfo.VideoType != ".3gp")
{
Res = "Failed! File type should be video file.";
}
else
{
MemoryStream target = new MemoryStream();
file.InputStream.CopyTo(target);
byte[] fileData = target.ToArray();
ProfInfo.VD = fileData;
}
}
else
{
ProfInfo.FileType = Path.GetExtension(file.FileName);
if (ProfInfo.FileType != ".png" && ProfInfo.FileType != ".jpeg" && ProfInfo.FileType != ".jpg" && ProfInfo.FileType != ".gif")
{
Res = "Failed! File type should be jpeg/jpg or png.";
}
else
{
MemoryStream target = new MemoryStream();
file.InputStream.CopyTo(target);
byte[] fileData = target.ToArray();
ProfInfo.DP = fileData;
}
}
}
string fname;
if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
//In this section I got error when file size > 2MB
string JsonRes = WebService.Postfile(ApiUrl + "Jobseeker/updateJbsProfileSummery?Token=" + Token, JsonConvert.SerializeObject(ProfInfo));
ResultInfo = JsonConvert.DeserializeObject<ResultInfo<string>>(JsonRes);
if (ResultInfo.ErrorCode == 200)
{
Res = "Success! " + ResultInfo.Info;
}
else
{
Res = ResultInfo.Info;
}
}
}
else
{
if (User.Identity.Name != "" && User.Identity.Name != null)
{
string[] arr = User.Identity.Name.Split('|');
Token = arr[0];
ProfInfo.ID = Convert.ToInt64(arr[3]);
}
string JsonRes = WebService.Postfile(ApiUrl + "Jobseeker/updateJbsProfileSummery?Token=" + Token, JsonConvert.SerializeObject(ProfInfo));
ResultInfo = JsonConvert.DeserializeObject<ResultInfo<string>>(JsonRes);
if (ResultInfo.ErrorCode == 200)
{
Res = "Success! " + ResultInfo.Info;
}
}
}
else
{
Res = "Failed! Information is not provided.";
}
}
catch (Exception ex)
{
Res = "Failed!" + ex.Message;
}
return Res;
}
#endregion
Is it any problem on Api solution webconfig file "maxRequestLength" not supported on target framework 4.0 If anyone solve my problem, Thank You In Advanced