如果您的uploadify 3.1在上传的时候报http error 302错误,则有可能是上传处理页面的权限没有正常执行。我用火狐的超级管理员账号上传信息,结果在调试的时候,发现uploadify 3.1的上传处理页面的登录信息居然是IE中的那个账号信息。另外,如果IE中的账号退出,则不能上传的。后来,我只好把上传处理页面的登录信息给去掉了,没有继承BasePage类了(很大的隐患哦)。
贴上部分代码:
uploadify 3.1上传初始:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FileUpload.ascx.cs" Inherits="Web.UserControl.FileUpload" %> <div id="<%=GetGuid%>"> <input type="file" name="<%=GetFileInputID%>" id="<%=GetFileInputID%>"/> <input type="hidden" name="<%=GetHiddenID%>" id="<%=GetHiddenID%>"/> <input type="hidden" name="<%=GetEditHiddenID%>" id="<%=GetEditHiddenID%>" value="<%=this.SetEditHiddenValue%>" /> <span id="<%=GetEditSpanID%>"> <%=this.SetEditSpan%> </span> <div id="<%=GetBitmapCutterID%>"></div> <script type="text/javascript"> var <%=GetGuid%>={ con:$("#<%=GetGuid%>"), delFunction:function(obj){ var currentId=$(obj).attr("rel"); //编辑时删除附件的函数 var ids=[]; var newIds=[]; $objEditHidden=<%=GetGuid%>.con.find("#<%=this.GetEditHiddenID%>"); var hideValues=$objEditHidden.val(); if(hideValues!='') { ids=hideValues.split(','); for(var i=0;i<ids.length;i++) { if((ids[i].toString())!=currentId&&(ids[i].toString())!='') { newIds.push(ids[i].toString()); } } } $objEditHidden.val(newIds.toString()); $(obj).closest("span[rel='"+currentId+"']").remove(); }, Init:function(){ <%=GetGuid%>.con.find("#<%=GetHiddenID%>").val("");//火狐下会自动保留上次的value值,一定要清空,否则程序会认为又有新上传的文件 $("#<%=GetFileInputID%>").uploadify({ debug:false, swf : '<%=Web.BasePage.BasePage.Url%>Js/uploadify/uploadify.swf', uploader : '<%=Web.BasePage.BasePage.Url%>Public/UploadFile.aspx' , buttonText:"选择", width:80, height:20, button_image_url:'<%=Web.BasePage.BasePage.Url%>Js/uploadify/img/bg.jpg',//背景设置了没有用,用一个小点代替,此参数必须存在,否则,会报禁止访问 fileSizeLimit:<%=this.FileSizeLimit%>, uploadLimit:<%=this.LimitCount%>, removeCompleted:<%=Convert.ToString(this.RemoveCompleted).ToLower()%>, auto:<%=Convert.ToString(this.AutoUpload).ToLower()%>, fileTypeExts:"<%=this.StrExt%>", formData:{ "type":"<%=(int)this.Type%>", "sessionId":"<%=Session.SessionID%>", "path":"<%=this.StrPath%>", "isSmall":"<%=this.IsSmall%>", "smallWidth":"<%=this.SmallWidth %>", "smallHeight":"<%=this.SmallHeight %>", "preStr":"<%=this.PreStr %>" }, onUploadSuccess:function(file, data, response){//file:文件对象 data:服务器端返回值 response:状态标志 var dataJson=eval('('+data+')'); if(dataJson.msg!="")//msg为文件上传后的路径 { $hideObj=<%=GetGuid%>.con.find("#<%=GetHiddenID%>"); var v=''; if($hideObj.val()==''||<%=Convert.ToString(this.RemoveHiddenValue).ToLower()%>) { v=escape(file.name)+','+file.size+','+dataJson.msg;//真实名字,文件大小Byte,上传后的路径 }else{ v='|'+escape(file.name)+','+file.size+','+dataJson.msg; } if(<%=Convert.ToString(this.RemoveHiddenValue).ToLower()%>) { $hideObj.val(v); }else{ $hideObj.val($hideObj.val()+v); } } }, onQueueComplete:function(){//队列上传完成后执行回调函数 if(!(<%=Convert.ToString(this.AutoUpload).ToLower()%>)) { //不为自动上传则执行 <%=this.OnQueueComplete %> } //是否调用可视化图片裁剪 if((<%=Convert.ToString(this.IsCallBitmapCutter).ToLower()%>)) { $hideObj=<%=GetGuid%>.con.find("#<%=GetHiddenID%>"); if($hideObj.val()!='') { $("#<%=this.GetBitmapCutterID%>").html(""); var fileInfoArr=[]; fileInfoArr=$hideObj.val().split(','); $.fn.bitmapCutter({ preStr:'<%=this.PreStr %>', src:'<%=Web.BasePage.BasePage.Url%>'+fileInfoArr[2], webSrc: fileInfoArr[2],//不包括虚拟目录的地址 virtualPath:'<%=Web.BasePage.BasePage.Url%>',//虚拟根目录 renderTo: '#<%=this.GetBitmapCutterID%>', cutterSize: { width: <%=this.CutWidth%>, height: <%=this.CutHeight%> }, onGenerated: function(data) { $hideObj.val(data.fileName+','+data.size+','+data.sourceSrc); }, rotateAngle: 90, lang: {clockwise:'顺时针旋转{0}度.'} }); } } } }); } } $(function(){ <%=GetGuid%>.Init(); <%=this.strMsg%> }); </script> </div>
uploadify 3.1文件处理页:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CommonClass.StringHander; using System.Text; using CommonClass.FileHandler; namespace Web.Public { /// <summary> /// 文件上传处理 /// </summary> public partial class UploadFile : System.Web.UI.Page//BasePage.BasePage//用其它浏览器登录信息居然是IE中的 { private int type = -1; private string sessionId = string.Empty; private string path = string.Empty; private int isSmall = 0; private int smallWidth = 0; private int smallHeight = 0; private string preStr = ""; protected void Page_Load(object sender, EventArgs e) { this.path = Request.Form["path"] ?? ""; this.type = Common.GetInt(Request.Form["type"] ?? "-1"); this.sessionId = Request.Form["sessionId"] ?? ""; this.isSmall = Common.GetInt(Request.Form["isSmall"] ?? "0"); this.smallWidth = Common.GetInt(Request.Form["smallWidth"] ?? "0"); this.smallHeight = Common.GetInt(Request.Form["smallHeight"] ?? "0"); this.preStr = Request.Form["preStr"] ?? ""; if (!IsPostBack) { this.InitData(); } } protected void InitData() { StringBuilder str = new StringBuilder(); HttpPostedFile file = Request.Files["Filedata"]; //判断保存路径是否存在,若不存在则新建 if (this.path.Length == 0||null==file) { return; } string newDirectoryPath = ComFile.GetSaveDirectory(Server.MapPath("~/"+this.path));//目录路径 string newName = string.Format("{0}.{1}", Guid.NewGuid(), ComFile.GetExtName(file.FileName)); string newFilePath = newDirectoryPath + newName; //此处的权限判断,在火狐下居然用的是ID的COOKIE登录信息。。。uploadify,bug //switch (this.type) //{ // case (int)SystemConfig.CommonState.FileType.企业创新: // if (!CheckRight("企业创新", "企业创新_添加") && !CheckRight("企业创新", "企业创新_修改")) // { // NoRightsInfo(); // return; // } // file.SaveAs(newFilePath); // break; // case (int)SystemConfig.CommonState.FileType.用户头像: // //去掉权限,普通员工可以上传 // //if (!CheckRight("用户管理", "用户添加") || !CheckRight("用户管理", "用户修改")) // //{ // // NoRightsInfo(); // // return; // //} // file.SaveAs(newFilePath); // break; // case (int)SystemConfig.CommonState.FileType.公告通知: // if (!CheckRight("系统设置", "公告通知_添加") && !CheckRight("系统设置", "公告通知_修改")) // { // NoRightsInfo(); // return; // } // file.SaveAs(newFilePath); // break; // case (int)SystemConfig.CommonState.FileType.周报月报: // if (!CheckRight("周报月报", "周报月报_添加") && !CheckRight("周报月报", "周报月报_修改")) // { // NoRightsInfo(); // return; // } // file.SaveAs(newFilePath); // break; //} file.SaveAs(newFilePath); if (newFilePath.Length>0&&System.IO.File.Exists(newFilePath)) { if (this.isSmall == 1) { //生成统缩略图 ComFile.MakeThumbnail(newFilePath,newDirectoryPath+this.preStr+newName,this.smallWidth,this.smallHeight,"W"); } str.Append(this.path + newName); } Response.Clear(); Response.Write(string.Format(@"{{'msg':'{0}'}}",str.ToString())); Response.End(); } } }