字符串长度超过maxJsonLength属性

时间:2019-02-07 08:03:17

标签: c# json asp.net-mvc-5

我有以下代码,由ajax调用,该代码将pdf转换为base64字符串,然后将结果作为json发送:

public object LoadPDF(string fileName)
{
    string filePath = Server.MapPath(new Uri(fileName).LocalPath);
    PdfLoadedDocument loadedDoc = new PdfLoadedDocument(filePath);
    MemoryStream stream = new MemoryStream();
    loadedDoc.Save(stream);

    byte[] docBytes = stream.ToArray();
    loadedDoc.Close(true);

    return Json(new { data = "data:application/pdf;base64," + Convert.ToBase64String(docBytes.ToArray()) });
}

此操作正常,但文件大于2MB时除外。我的ajax成功出现以下错误消息:

  

使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了在maxJsonLength属性上设置的值。

有人为此工作吗?

0 个答案:

没有答案
相关问题