Fix jqueryify plugin in Firefox, 360 browser cannot upload file problem

Source: Internet
Author: User

Repeated debugging, found that the problem is:jquery uploadify under IE can be uploaded normally, in the implementation of asynchronous upload, each file will be submitted to the server when uploading a request. Each request requires security verification, session and Cookie checksum. Yes, that's it. Since the jquery uploadify is uploaded using Flash, IE automatically bundles the local cookie store to the server each time a data flow request is sent to the background. But Firefox, Chrome won't do it, and they'll think it's not safe. Ha, that's the reason.

Workaround, add these two methods on the Global.asax.cs file:

 protected voidApplication_BeginRequest (Objectsender, EventArgs e) {            Try            {                //solve the problem of Firefox, 360 browser using uploadify upload session missing                stringSession_param_name ="ASPSessionID"; stringSession_cookie_name ="Asp.net_sessionid"; if(Request[session_param_name]! =NULL) {Updatecookie (Session_cookie_name, Request[session_param_name]); }                stringAuth_param_name ="AUTHID"; stringAuth_cookie_name =Formsauthentication.formscookiename; if(Request[auth_param_name]! =NULL) {Updatecookie (Auth_cookie_name, Request[auth_param_name]); }            }            Catch { }        }        Private voidUpdatecookie (stringCookie_name,stringcookie_value) {HttpCookie Cookie=Request.Cookies.Get (cookie_name); if(Cookie = =NULL) {Cookie=NewHttpCookie (cookie_name); } cookie. Value=Cookie_value;        Request.Cookies.Set (cookie); }

Page script, the first Session,cookie information that the current user logged in is sent to the server to verify:

varFormData ={attachmentguid:attachmentguid, ASPSessionID:'@Session. SessionID', AUTHID:'@ (Request.cookies[formsauthentication.formscookiename] = = null? string. Empty:request.cookies[formsauthentication.formscookiename]. Value)'                }; $('#uploadify'). uploadify ({'FormData': FormData,//other parameters sent to the background are specified by Formdata                    'Uploader':'/syscommon/attachmentupload',//pages processed in the background                    'Auto':false,//automatically upload after selecting a file                    'removecompleted':false,//progress bar                    'filetypeexts':'*.gif, *.jpg, *.png',//allow file suffixes to be uploaded                    'Uploadlimit':1,//number of files allowed to upload                    'SizeLimit':3072000,//allow file size to be uploaded                    'SWF':'/scripts/uploadify/uploadify3.2.1/uploadify.swf',//Specify SWF file                    'ButtonText':'Select File',//the text that the button displays                    'Buttonclass':'Uploadify-button',//the style of the button display                    'Multi':true,//set to True to allow multiple file uploads                    'Filetypedesc':'Uploading Files',//text displayed in the File Type drop-down menu at the bottom of the Browse window                    'Queueid':'Filequeue',//upload File page, the ID of the element you want to use as the file queue, default to False auto-generated, without #                    'OnComplete': Function (Event, Queueid, fileobj, response, data) {                        //triggered when a single file upload is completeConsole.log ("msg: Single file upload. ")                        varJSON = eval ("("+ Response +")");                        Console.log (JSON);                        Console.log (response);                        Console.log (Fileobj); Console.log (Event);                    Console.log (data); },                    'OnSelect': function (file) {//When you select a file, each upload task is triggered when you add it to the queue. Console.log ("msg: After selecting a file, add each upload task to the queue. ") Console.log (file)},'Onselecterror': Function () {//The event is triggered when a file return error is selected. Each file that returns an error triggers the event. Console.log ("msg: The event is triggered when a file returns an error. Each file that returns an error triggers the event. ")                    },                    'OnCancel': function (file) {//When you click the Close button of a file in the file queue or click Cancel Upload, the file parameter is the object that is being canceled for uploading. Console.log ("msg: When you click the Close button of a file in the file queue or click Cancel upload. ") Console.log (file)},'OnInit': Function () {//triggered at the end of the first initialization uploadify. Console.log ('msg: initial initialization'); },                    'onuploadsuccess': function (file, data, response) {//triggered when the file upload is successful.                         varJSON =Jquery.parsejson (data); Console.log ('msg: File Upload successful');                        Console.log (file) console.log (JSON) Console.log (response)                        alert (json.resultmsg); if(JSON.ISSUCC) {$ ("#OpenEditId"). Dialog ("Destroy"); }                    },                    'OnError': Function (type, info) {//triggered when an outgoing mistake occurs on a single file. Console.log ('msg: Error on file');                        Console.log (type);                    Console.log (info); },                    'Onfallback': Function () {//triggered when the current browser does not support flash during initialization of uploadify. Console.log ('msg: triggered when the current browser does not support Flash'); },                    'Onswfready': Function () {//triggered when the Flash file is loaded successfully. Console.log ('Msg:flash file loaded successfully'); }                })

The problem is solved by this way.

protected void Application_BeginRequest (object sender, EventArgs e)
{
Try
{
Solve the problem of Firefox, 360 browser using uploadify upload session missing
String session_param_name = "ASPSessionID";
String session_cookie_name = "Asp.net_sessionid";
if (request[session_param_name]! = NULL)
{
Updatecookie (Session_cookie_name, Request[session_param_name]);
}
String auth_param_name = "AUTHID";
string auth_cookie_name = Formsauthentication.formscookiename;
if (request[auth_param_name]! = NULL)
{
Updatecookie (Auth_cookie_name, Request[auth_param_name]);
}
}
Catch {}
}

private void Updatecookie (String cookie_name, String cookie_value)
{
HttpCookie cookie = Request.Cookies.Get (cookie_name);
if (cookie = = null)
{
cookie = new HttpCookie (cookie_name);
}
Cookies. Value = Cookie_value;
Request.Cookies.Set (cookie);
}

Fix jqueryify plugin in Firefox, 360 browser cannot upload file problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.