2014-02-21 29 views
1

我在我的網站上使用plupload flash runtime將文件作爲附件上傳並通過電子郵件發送。該網站在Chrome瀏覽器,IE9和IE11上運行良好,但不在IE8上運行。我的大部分用戶都將使用IE8。我一直在嘗試許多不同的事情,但似乎沒有任何工作。任何人都可以請建議我任何解決方案plupload flash運行時不能在IE8上工作

這是我的JavaScript代碼,我上傳的文件發生。

modules.compose = (function() { 
"use strict"; 

var config = { 
    id: '', 
    requestToken: $('meta[name="__AntiForgeryToken"]').attr('content'), 
    runtimes: 'gears,flash,silverlight,browserplus,html5', 
    maxFileSize: '200mb', 
    maxQueueSize: 10485760, 
    chunkSize: '1mb', 
    pingFrequency: 100000, 
    isUploaderOpen: false 
}, 
bindUploader = function() { 
    $("#uploader").pluploadQueue({ 
     // General settings 
     runtimes: config.runtimes, 
     url: '/upload.ashx' + '?id=' + config.id, 
     max_file_size: config.maxFileSize, 
     chunk_size: config.chunkSize, 
     unique_names: false, 
     headers: { '__AntiForgeryToken': config.requestToken }, 

     // Browse filters 
     filters: [ 
      { title: "All files", extensions: "*.*" }, 
      { title: "Image files", extensions: "jpg,gif,png,tiff" }, 
      { title: "XML files", extensions: "xml" }, 
      { title: "PDF documents", extensions: "pdf" }, 
      { title: "Zip files", extensions: "zip" }, 
      { title: "Text files", extensions: "txt,log" }, 
      { title: "Powerpoint documents", extensions: "ppt,pptx,pptm,potx,potm,ppam,ppsx,ppsm,sldx,sldm,thmx" }, 
      { title: "Excel documents", extensions: "xls,xlsx,xlsm,xltx,xltm,xlsb,xlam" }, 
      { title: "Word documents", extensions: "doc,docx,docm,dotx,dotm" },     
     ], 
     preinit: { 
      Init: function (up, info) { 
       $('.plupload_header, .plupload_start').remove(); 
      } 
     }, 
     init: { 
      UploadProgress: function (up, file) { 
       bumpProgress(up, file); 
      }, 
      StateChanged: function (up) { 
       if (up.total && up.files && up.total.uploaded === up.files.length) { 
        var parent = $('#upload-status').parent(); 
        $('#upload-status').fadeOut('slow').remove(); 
        $('#send-status').appendTo(parent).fadeIn('slow'); 

        __doPostBack('ctl00$Content$btnSendMessage', ''); 
       } 
      }, 
      FilesAdded: function (up, files) { 
       var i = 0; 
       while (i++ < up.files.length) { 
        $('#btnSendMessage').removeAttr("disabled"); 
        var ii = i; 
        while (ii < up.files.length) { 
         if (up.files[i - 1].name == up.files[ii].name) { 
          up.removeFile(up.files[ii]); 
         } else { 
          ii++; 
         } 
        } 
       } 
      }, 
      QueueChanged: function (up) { 
       if (up.total.size > config.maxQueueSize) { 
        $('#upload-warning-modal').modal('show'); 

        if (up.total.queued - 1 >= 0) { 
         up.removeFile(up.files[up.total.queued - 1]); 
        } 
       } 
      } 
     }, 

     // Flash settings 
     flash_swf_url: '/assets/js/plupload/plupload.flash.swf', 

     // Silverlight settings 
     silverlight_xap_url: '/assets/js/plupload/plupload.silverlight.xap' 
    }); 
}, 
bindAddAttachments = function() { 
    $('#btnAddAttachments').click(function (e) { 
     e.preventDefault(); 

     if (!config.isUploaderOpen) { 
      bindUploader(); 
      $('#uploader').show(); 

      config.isUploaderOpen = true; 
     } 

     $(this).attr('disabled', 'disabled'); 
    }); 
}, 
bindSendMessage = function() { 
    $('#btnSendMessage').click(function (e) { 
     e.preventDefault(); 

     if (!Page_ClientValidate()) { 
      return; 
     } 

     $('.plupload_filelist_footer').css('display', 'none'); 

     $('#uploader').block({ 
      message: $('#upload-status'), 
      css: { 
       padding: 0, 
       margin: 0, 
       width: '50%', 
       top: '50%', 
       left: '35%', 
       textAlign: 'left', 
       color: '#000', 
       border: '0', 
       backgroundColor: 'transparent', 
       cursor: 'wait' 
      } 
     }); 

     $('input[type="text"], textarea').prop('readonly', true).addClass('disabled'); 

     $('#btnSendMessage').button('loading'); 

     var queue = $("#uploader").pluploadQueue(); 

     if (queue) { 
      queue.start(); 
     } else { 
      __doPostBack('ctl00$Content$btnSendMessage', ''); 
     } 
    }); 
}, 
bumpProgress = function (up, file) { 
    if (up.total.percent >= 80) { 
     $('#upload-status .progress').removeClass('progress-info').addClass('progress-success'); 
    } 

    $('#upload-status .progress .bar').css('width', up.total.percent + '%'); 
}, 
bindTextareaLimit = function() { 
    $('#txtMessage').limit('2000', '#charsLeft'); 
}, 
initAttachmentsButton = function() { 
    $('#btnAddAttachments').prop('disabled', ''); 
}, 
initPing = function() { 
    (function ping() { 
     $.get("/ping.ashx"); 
     setTimeout(ping, config.pingFrequency); 
    })(); 
}; 

return { 
    init: function (options) { 
     config = $.extend({}, config, options || {}); 

     $(function() { 
      initAttachmentsButton(); 
      initPing(); 
      bindSendMessage(); 
      bindAddAttachments(); 
      bindTextareaLimit(); 
     }); 
    }, 
    validateRecipientEmail: function (sender, args) { 
     var proxy = new ServiceProxy('/Default.aspx/', { async: false }); 

     proxy.invoke(
     'IsValidRecipient', 
     { recipient: $('#txtRecipient').val() }, 
     function (result) { 
      return (args.IsValid = result.d); 
     }); 
    }, 
    validateSenderEmail: function (sender, args) { 
     var proxy = new ServiceProxy('/Default.aspx/', { async: false }); 

     proxy.invoke(
     'IsValidSender', 
     { sender: $('#txtSender').val() }, 
     function (result) { 
      return (args.IsValid = result.d); 
     }); 
    } 
}; 
}()); 

回答

0

希望我不會太晚。最近有同樣的問題。問題是,你使用
headers: { '__AntiForgeryToken': config.requestToken }, 但通過規範它不是在HTML4運行時支持:

http://www.plupload.com/docs/Options#runtimes

頭 與每個上傳要求定製的HTTP頭傳遞的方式。該選項是簡單的標題名稱及其值的鍵/值對的集合。

不支持html4運行時。 閃光燈和銀光燈運行時需要特殊的操作模式。

由於IE8可以禁用所有其他的方式來上傳文件它將使用HTML4 runtime,它不具有任何合法的方式如何設置防僞標記。因此,您的server-side會認爲您的發送文件不安全,因爲它沒有antiForgery令牌,並且帶有禁止HTTP狀態。

結論 - 您無法在IE8中使用帶有plupload的AntiForgery令牌,因爲它是如何在ASP.NET MVC中構建的。