I'm trying to read a large-ish (2.3mb) json file and return it as a json on the web.
string path = AppDomain.CurrentDomain.BaseDirectory @"GeoJson/MaliCommunes.geo.json";
string json;
using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding("iso-8859-1")))
{
json = sr.ReadToEnd();
}
JavaScriptSerializer JsonSerializer = new JavaScriptSerializer();
object data = JsonSerializer.DeserializeObject(json);
return new JsonResult()
{
Data = data,
ContentType = "application/json",
ContentEncoding = Encoding.UTF8,
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
MaxJsonLength = Int32.MaxValue
};
This works on localhost, but when I upload it to the server, I get a 500 error 'File not found' on this line using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding("iso-8859-1")))
I've tried the following in web config:
- Add maxRequestLength in the httpRuntime
- Add maxJsonLength for jsonSerialization
My guess is that either the file is curropted (it does have french accented characters) or that the file is too big and is causing issues in the server.
CodePudding user response:
- Check the name of the big json file more carefully. it can have an extension that is invisible. Check the path by trying to open the json file manually. Just type the full path using Windows explorer.
- Check the permissions at the security tab of the big json file, and compare them with the permissions of json file that works without any problem.
CodePudding user response:
I removed the french accents and it worked