【问题标题】:ASP.NET MVC Uploadify - Http 302 in FirefoxASP.NET MVC Uploadify - Firefox 中的 Http 302
【发布时间】: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


【解决方案1】:

从这里得到答案: Uploadify (Session and authentication) with ASP.NET MVC

您需要连同它一起发送 Auth Cookie 和 Session ID。 Chrome 正在这样做,但不是 Firefox。

【讨论】:

    【解决方案2】:

    您可以拥有一个控制器,您可以通过在控制器级别添加属性来禁用其身份验证。您可以为文件上传操作编写上传操作。

    我猜你只关心在某些服务器文件夹上上传文件。请看下面的代码。这对我有用。

    [AllowAnonymous]
    public class CustomUploadifyController : Controller
    {
        [HttpPost]
        public string CaseDocumentUpload(string CaseNumber)
        {
            var file = Request.Files["Filedata"];
    
            System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Temp\" + CaseNumber));
            string savePath = Server.MapPath(@"~\Temp\" + CaseNumber + @"\" + file.FileName);
            file.SaveAs(savePath);
    
            return file.FileName;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-05
      • 2011-11-21
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多