【发布时间】:2012-02-01 20:20:36
【问题描述】:
我的uploadify (v.2.1.4) 和我的MVC 3 项目存在配置问题。这是返回 HTTP 302 代码的代码。
@{string auth = @Request.Cookies[FormsAuthentication.FormsCookieName] == null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value;}
$("#fileuploader").uploadify({
uploader: '@Url.Content("~/Scripts/uploadify.swf")',
script: '@Url.Action("Upload", "Control")',
scriptData: { token: "@auth" },
fileDataName: 'file',
buttonText: 'Upload file',
multi: false,
sizeLimit: 22222222222,
simUploadLimit: 1,
cancelImg: '@Url.Content("~/Images/uploadify-cancel.png")',
auto: true,
onError: function(event, queueID, fileObj, errorObj) {
alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
},
onComplete: function (event, queueId, fileObj, response, data) {
alert(response);
}
});
public class ControlController : Controller
{
[HttpPost]
public ActionResult Upload(string token, HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var appData = Server.MapPath("~/app_data");
var filename = Path.Combine(appData, Path.GetFileName(file.FileName));
file.SaveAs(filename);
}
return Json(true);
}
}
1) 控制器的动作没有被触发
2) 我找到了该主题 Getting Uploadify to work with asp.net-mvc,但如果我将该属性用于我的控制器,我会看到“AuthenticationToken”为空(我已登录)
3) 如果我将上传选项“method”设置为“post”,我会得到#2032 error
编辑
控制器是管理控制器,所以我使用该属性:
protected override bool AuthorizeCore(HttpContextBase httpContext) {
if (!HttpContext.Current.User.Identity.IsAuthenticated)
return false;
if (admin && !um.IsAdmin(HttpContext.Current.User.Identity.Name))
return false;
return true;
}
返回真。我注意到,如果我删除此属性,则上传开始工作。但我需要那个属性
【问题讨论】:
-
@Andrew Barber:嗨,安德鲁!你有这个运气吗?我遇到了同样的问题。
-
@jaj 不是我;是托尼。但他也收到了您的评论通知。
标签: c# asp.net-mvc-3 uploadify