About SWFUpload in Firefox (FF, Firefox), the error 302,session,cookie

Source: Internet
Author: User
Tags file upload httpcontext

The most recent problem with multiple file uploads has been the Multifile.js plugin with jquery, but because the plugin can't show the progress bar, the project is actually essential to the progress bar

Plus really is not willing to spend time to write file upload progress, had to find the swfupload with flash upload file plug-ins, in IE upload multiple files very smooth, but under the Firefox

But always reported 302 errors, through 1100 degrees, suddenly look back to Google toss, just understand the reason, I would like to take this subtotal down, after all, upload with progress bar function is too common, the first receive

Means

Because SWFUpload is uploaded by Flash,flash in IE will be the current page of cookies to upload.aspx, but Chrome, Firefox will not send the current page cookies to the upload.aspx. because the session is implemented by the SessionID stored in the cookie , This is because the current page cookie is not passed to the flash request upload.aspx, so the requested file sent to the UPLOAD.ASHX is a new session, of course, this session is not logged in.

The idea of solving this problem is also very simple, that is manually pass the SessionID to the server, and then the server read out SessionID reload session. In fact, the solution to the problem has been given in the demo swfupload, which is to set the Post_params parameter in the SWFUpload constructor:


SWFU = new SWFUpload ({
                    //backend Settings
                    upload_url: "/upload.aspx",
                    post_params: {
                        "aspsessid": " <%=session.sessionid%> "},


The key-value pairs that are set in the Post_params are passed to the Upload.aspx in form form forms, which means that SWFUpload provides an interface to increase the custom request parameters for the request.

If the site also uses the Membership FormsAuthentication verification, then also need to authid also according to the SessionID method processing

SWFU = new SWFUpload ({
                    //backend Settings
                    upload_url: "/upload.ashx",
                    post_params: {
                        "aspsessid": " <%=session.sessionid%> "},
                         " Authid ":" <%=request.cookies[formsauthentication.formscookiename ". Value%> ",


The above code writes the SessionID of the current page to the Aspsessid value, and when the user uploads the file, Aspsessid is delivered to the server, adding the following code to the application_beginrequest of Global.asax:
protected 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 (Sessi
                On_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 (Exception) {} 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[au
                Th_param_name]);
                    else if (Httpcontext.current.request.querystring[auth_param_name]!= null) {
                Updatecookie (Auth_cookie_name, Httpcontext.current.request.querystring[auth_param_name]); } catch (Exception) {}} void Updatecookie (String co Okie_name, String cookie_value) {HttpCookie cookie = HttpContext.Current.Request.Cookies.Get (cookie_n
            AME);
                if (cookie = = null) {HttpCookie cookie1 = new HttpCookie (Cookie_name, Cookie_value);
            RESPONSE.COOKIES.ADD (COOKIE1); } else {cookie.
                Value = Cookie_value;
            HttpContext.Current.Request.Cookies.Set (cookie); }
        }

Principle: When a user requests to reach the ASP.net engine, the Application_BeginRequest method is invoked first, in the method to see if the client is submitted Aspsessid, if so Writes the value of the Aspsessid to the cookie ("Asp.net_sessionid" as the key because the SESSIONID in asp.net is stored in a cookie of "Asp.net_sessionid" as key). Application_BeginRequest method can be read from the cookie to "Asp.net_sessionid" the value of the page to restore the session.

If the site is authenticated using Windows, post_params:{

Aspsessid: "<%=session.sessionid%>", so that you do not need to write any method in Application_BeginRequest.

Related reading

3.2 Version uploadify detailed examples (including FF and IE session issues)




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.