jquery uploadify在ie下能夠正常上傳,在實現異步上傳的時候,每個文件在上傳時都會提交給服務器一個請求。每一個請求都須要安全驗證,session 和cookie的校驗。是的,就是這樣。因爲jquery uploadify是藉助flash來實現上傳的,每一次向後臺發送數據流請求時,ie會自動把本地cookie存儲捆綁在一塊兒發送給服務器。但 firefox、chrome不會這樣作,他們會認爲這樣不安全。javascript
首先須要對global.asxa添加以下內容html
protected void Application_BeginRequest(object sender, EventArgs e)
2 {
3 /* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */
4 try
5 {
6 string session_param_name = "ASPSESSID";
7 string session_cookie_name = "ASP.NET_SessionId";
8
9 if (HttpContext.Current.Request.Form[session_param_name] != null)
10 {
11 UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
12 }
13 else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
14 {
15 UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
16 }
17 }
18 catch
19 {
20 }
21
22 try
23 {
24 string auth_param_name = "AUTHID";
25 string auth_cookie_name = FormsAuthentication.FormsCookieName;
26
27 if (HttpContext.Current.Request.Form[auth_param_name] != null)
28 {
29 UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
30 }
31 else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
32 {
33 UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
34 }
35
36 }
37 catch
38 {
39 }
40 }
41
42 private void UpdateCookie(string cookie_name, string cookie_value)
43 {
44 HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
45 if (null == cookie)
46 {
47 cookie = new HttpCookie(cookie_name);
48 }
49 cookie.Value = cookie_value;
50 HttpContext.Current.Request.Cookies.Set(cookie);
51 }java
初始化頁面上傳插件代碼以下jquery
1 <script type="text/javascript"> 2 var auth = "@(Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value)"; 3 var ASPSESSID = "@Session.SessionID"; 4 5 $(function () { 6 $('#upload').uploadify({ 7 'formData': { 'folder': '/Upload', 'ASPSESSID': ASPSESSID, 'AUTHID': auth }, 8 'buttonText': '瀏覽', 9 'buttonClass': 'browser', 10 'fileSizeLimit' : '100KB', 11 'fileTypeExts': '*.xls;*.xlsx', 12 'removeCompleted': false, 13 'swf': '@Url.Content("~/Scripts/Uploadify/uploadify.swf")', 14 'uploader': '/Upload', 15 'onUploadSuccess': function (file, data, response) {} 16 }); 17 }); 18 </script>
轉載自:http://www.cnblogs.com/monsterworks/archive/2013/01/22/2871316.htmlchrome