[英]MVC 3 Uploadify HTTP 302 error
我在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可以與asp.net-mvc一起使用 ,但是如果我對該控制器使用該屬性,則會看到“ AuthenticationToken
”為空(我已經登錄)
3)如果我將uploadify選項' 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;
}
返回true。 我注意到,如果刪除此屬性,則上傳開始工作。 但是我需要那個屬性
it's help you.
var auth = "@(Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value)";
var ASPSESSID = "@(Session.SessionID)";
$("#uploadifyLogo").uploadify({
...
'scriptData': { 'ASPSESSID': ASPSESSID, 'AUTHID': auth }
});
在Global.asax中:
protected void Application_BeginRequest(object sender, EventArgs e)
{
/* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */
try
{
string session_param_name = "ASPSESSID";
string session_cookie_name = "ASP.NET_SessionId";
if (HttpContext.Current.Request.Form[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
}
else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
}
}
catch
{
}
try
{
string auth_param_name = "AUTHID";
string auth_cookie_name = FormsAuthentication.FormsCookieName;
if (HttpContext.Current.Request.Form[auth_param_name] != null)
{
UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
}
else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
{
UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
}
}
catch
{
}
}
private void UpdateCookie(string cookie_name, string cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
if (null == cookie)
{
cookie = new HttpCookie(cookie_name);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.