Как читать maxRequestLength из javascript webconfig - PullRequest
0 голосов
/ 08 ноября 2019

я хотел знать, как читать maxRequestLength в моем коде

  <system.web>
    <httpRuntime maxRequestLength="20480"  />
  </system.web>

это мой код прямо сейчас


        function formatBytes(bytes) {
            var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
            if (bytes == 0) return 'n/a';
            var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
            if (i == 0) return bytes + ' ' + sizes[i];
            return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
        }


        function UploadFile() {
            debugger;

            var file = document.getElementById("<%=documentUpload.ClientID%>");
            file1 = formatBytes(file.files[0].size);
             var maxLength = ConfigurationManager.GetSection("system.web/httpRuntime");
            var size = maxLength.MaxRequestLength;

             if (file1 > size) {
                 alert("The uploaded file size exceeds limit and cannot be uploaded.");
                 document.getElementById("<%=documentUpload.ClientID%>").value = '';
                 return false;
             }
             __doPostBack($('#<%=UploadFileBtn.ClientID %>').attr('name'), '');

        }

похоже, он не работает! Кто-нибудь может указать, что я делаю не так? Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...