jquery Uploadify solutions that cannot be uploaded under Firefox (. NET version)

Source: Internet
Author: User
Tags httpcontext

Come on, let's find out.

One, jquery uploadify self-Introduction:

(1), hello everyone, I am the jquery plugin large family in charge of implementing asynchronous upload plug-in, I am not the only, but a better use of a paragraph.

(2), my function:

Supports single-file or multi-file uploads to control the number of files uploaded concurrently

Support the use of various languages on the server side, such as Php,.net,java ...

Configurable upload file type and size limit via parameters

Parameters can be configured to automatically upload when a file is selected

Easy to scale, control the callback function for each step (OnSelect, OnCancel ...)

Control appearance through interface parameters and CSS

Uploadify Home Address: http://www.uploadify.com/on this page you can learn more about him.

(3), my usage:

Go to baidu.com,google.com Search search, a lot.

Second, Firefox under my fault, is my problem?

jquery uploadify in IE can be normal upload, 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.

Find out why, in let's understand two concepts:

(1), Session:

Sessions, also known as session state, are the most commonly used state in a web system to maintain some information related to the current browser instance. For example, we can put the username of the logged-in user in the session, so that we can determine whether the user is logged in by judging a key in the session, and how many user names are logged in.

We know that the session for each client (or browser instance) is a "person", the first time a user establishes a connection with the Web server, the server will give the user a sessionid as the identity. SessionID is a random string of 24 characters. Each time the user submits the page, the browser will include the SessionID in the HTTP header to the Web server, so that the Web server can distinguish between the client on the current request page. So, what are the storage SessionID modes that ASP. NET 2.0 provides?

(2), cookies, and sometimes their plural forms of cookies, which are data (usually encrypted) stored on the user's local terminal by certain websites in order to identify the user and track the session.

Third, the solution

In the Global.asax file, write the following code:

void Application_BeginRequest (object sender, EventArgs e)
{
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 {
}

Here is the authentication
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);
}
Cookies. Value = Cookie_value;
HttpContext.Current.Request.Cookies.Set (cookie);//Reset the cookie value in the request to assign the server-side session value to it
}

/*---------------------------aspx page-side code---------------------------------*/

This.hfAuth.Value = Request.cookies[formsauthentication.formscookiename] = = null? String. Empty:request.cookies[formsauthentication.formscookiename]. Value;

This.hfAspSessID.Value = Session.SessionID;

Save the session value and the authentication value to the client control, then you can get these two values through JS, and then pass to the following plug-in JS initialization program.

(Choosing to store session values in a control is also a concern for clients to disable cookies.) )

/*-----------------------------The following is the JS code----------------------------------*/

Initupload:function (auth, Aspsessid) {
$ ("#uploadify"). Uploadify ({
Uploader: ' scripts/jqueryplugins/infrastructure/uploadify.swf ',
Script: ' Handlers/resourcehandler.ashx? Optype=uploadresource ',
Cancelimg: ' Scripts/jqueryplugins/infrastructure/cancel.png ',
Queueid: ' Filequeue ',
SizeLimit: ' 21480000000 ',
Wmode: ' Transparent ',
Fileext: ' *.zip,*.jpg, *.rar,*.doc,*.docx,*.xls,*.xlsx,*.png,*.pptx,*.ppt,*.pdf,*.swf,*.txt ',
Auto:false,
Multi:true,
Scriptdata: {aspsessid:aspsessid, Authid:auth},

...//More configuration items, you can view the official configuration document

When the plug-in initialization, the local recorded session value, and the authentication value to the initialization method, parameter assignment, so that each time the asynchronous request to upload a file, the corresponding session value is included in the request file.

----------------------the above contents see http://www.cnblogs.com/mbailing/archive/2011/03/30/uploadify.html

Other problems encountered by Uploadif:

Ps1:ajax to the ashx parameter, by default the method is passed the value of the post,

Script can provide URL pass parameters. Used to pass a get parameter. For example:

Index.jsp?id=1&action=uploadify can be set to:

' Script ': ' index.jsp ',

' Scriptdata ': {' id ': 1, ' action ': ' Uploadify '},

To get the parameters in the Scriptdata in the background, the method must be set to get.

Ps2:oncomplete the parameter of the return value. As follows:

oncomplete: Function (event, Queueid, Fileobj,response) {

alert (response); }

-------------the above contents see http://www.cnblogs.com/pinnasky/archive/2010/06/02/1750089.html

jquery Uploadify solutions that cannot be uploaded under Firefox (. NET version)

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.