我知道這是一個很老的問題,但今天我有完全相同的問題,所以我會回答它。
Firefox的Flash plg中存在一個錯誤。上傳文件時不發送cookie。 我的解決方案:
1)創建新的授權屬性
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class FlashAuthorizeAttribute : AuthorizeAttribute
{
private const string AUTH_TOKEN = "AuthenticationToken4Flash";
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
{
string authToken = httpContext.Request.Params[AUTH_TOKEN];
if (authToken != null)
{
FormsAuthenticationTicket authForm = FormsAuthentication.Decrypt(authToken);
if (authForm != null)
{
FormsIdentity formIdentity = new FormsIdentity(authForm);
string[] userRoles = System.Web.Security.Roles.GetRolesForUser(formIdentity.Name);
GenericPrincipal userPrincipal = new GenericPrincipal(formIdentity, userRoles);
httpContext.User = userPrincipal;
}
}
return base.AuthorizeCore(httpContext);
}
}
2)控制器
[FlashAuthorize]
public ActionResult AsyncUpload()
{
HttpPostedFileBase file = Request.Files[0];
}
3)修改JS(FORMDATA,scriptData沒有工作的我,所以我加了查詢字符串)
upload_url: '@Url.Action("AsyncUpload", "Profile")' +'?AuthenticationToken4Flash=' + '@(Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value)',
我希望能幫到別人
顯示爲您的makeAsyncUploader函數和您的AsyncUpload conotroller操作 –
您是否可以包含來自Controller的一些代碼? – learning