【发布时间】:2023-03-20 19:24:01
【问题描述】:
我在我的 ASP.NET MVC 4.5 项目中使用 Jquery Uploadify 插件来实现附件功能。
该插件在 IE 和 Chrome 中运行良好;但是用户报告说文件没有在 Firefox、Safari 和 Opera 中上传。 Uploadify 返回“Http 302”响应,我搜索了论坛和博客,但没有运气。
许多建议的解决方案适用于 PHP 用户。下面是 jQuery 代码。我正在调用的操作方法没有“授权”属性。如果有人有任何想法,请告诉我。
$('#file_upload').uploadify({
'overrideEvents': ['onSelectError', 'onDialogClose'],
'formData': {'id': tid },
'swf': '/Scripts/uploadify/uploadify.swf',
'uploader': "/workitem/upload",
'fileDataName': 'file',
'fileTypeDesc': 'File',
'fileTypeExts': '*.jpg; *.jpeg; *.tiff; *.gif; *.bmp; *.png; *.pdf; *.doc; *.docx; *.docm; *.xls; *.xlsx; *.xlsm; *.ppt; *.pptx; *.txt',
'auto': false,
'multi': true,
'buttonText': 'BROWSE',
'queueSizeLimit': 10,
'sizeLimit': 1073741824,
'uploadLimit': 10,
'removeCompleted': true,
'queueID': 'queueContainer',
'onSelectError': function (a, b, c) {
var errorMsg;
if (b == -100)
errorMsg = 'You have reached the maximum number of files selected.';
else if (b == -110)
errorMsg = 'The file selected exceeds the file size limit.'
else if (b == -120)
errorMsg = 'The file selected has zero bytes and cannot be uploaded.'
else if (b == -130)
errorMsg = 'An invalid file type has been selected.'
},
'onUploadError': function (file, errorCode, errorMsg, errorString) {
alert(errorMsg);
}
});
编辑: 在使用 Firefox 浏览时使用 Fiddler 进行进一步分析时,使用“/Account/Login?ReturnUrl=%2fworkitem%2fupload”的位置路径捕获了 302 请求。这表明用户未通过身份验证或会话丢失;但是,当使用 HTTP 200 的 Chrome 请求时被捕获。有谁知道为什么会这样?
【问题讨论】:
-
您能否发布控制器的相关位,因为它看起来需要经过身份验证的用户。
-
在 Fiddler 而不是浏览器中获取重定向表明 Chrome 正在发送 Fiddler 未发送的身份验证 cookie。你能确认一下吗?
-
是的,看来我需要发送 Auth Cookie 和会话 ID。 Chrome 正在这样做,但不是 Firefox。
标签: jquery asp.net-mvc asp.net-mvc-4 uploadify