[CLOSED] MultiUpload with Firefox - Unauthorized

  1. #1

    [CLOSED] MultiUpload with Firefox - Unauthorized

    Hi,
    This is my sample:
    Test.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    <script runat="server">
        protected void MultiUpload1_FileUpload(object sender, FileUploadEventArgs e)
        {
            System.Threading.Thread.Sleep(3000); // for testing purposing only
            X.Msg.Notify("File is uploaded", "Name: " + e.FileName).Show();
        }
    </script>
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Simple MultiUpload - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
        <script type="text/javascript">
            var uploadError = function (item, file, errorCode, message) {
                alert("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
            };
    
            var fileSelectionError = function (item, file, errorCode, message) {
                alert("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />        
    
            <h1>Simple MultiUpload</h1>
            
            <ext:MultiUpload 
                ID="MultiUpload1" 
                runat="server"
                OnFileUpload="MultiUpload1_FileUpload"
                AutoStartUpload="true"
                FileDropAnywhere="true"
                FileSizeLimit="15 MB"
                FileTypes="*.*"
                FileTypesDescription="All Files"
                FileUploadLimit="100"
                FileQueueLimit="0">
                <Listeners>
                    <UploadStart Handler="Ext.Msg.wait('Uploading...');" />
                    <UploadError Fn="uploadError" />
                    <FileSelectionError Fn="fileSelectionError" />
                    <UploadComplete Handler="Ext.Msg.hide();" />
                </Listeners>
            </ext:MultiUpload>
         </form>     
    </body>
    </html>
    Web.config
    <?xml version="1.0"?>
    <configuration>
        <system.web>
          <httpHandlers>
            <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
          </httpHandlers>
    
          <httpModules>
            <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
          </httpModules>
    
          <pages>
            <controls>
              <add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" />
            </controls>
          </pages>
          <compilation debug="true" targetFramework="4.0" />
          
          <authorization>
            <deny users="?" />
          </authorization>
    
          <authentication mode="Windows"/>
    
        </system.web>
     
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
    
        <modules>
          <add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" />
        </modules>
    
        <handlers>
          <add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
        </handlers>
      </system.webServer>
      
    </configuration>
    and Global.aspx
    <%@ Application Language="C#" %>
    
    <script runat="server">
        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 (Exception)
            {
                Response.StatusCode = 500;
                Response.Write("Error Initializing Session");
            }
    
            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 (Exception)
            {
                Response.StatusCode = 500;
                Response.Write("Error Initializing Forms Authentication");
            }
        }
        void UpdateCookie(string cookie_name, string cookie_value)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
            if (cookie == null)
            {
                cookie = new HttpCookie(cookie_name);
                HttpContext.Current.Request.Cookies.Add(cookie);
            }
            cookie.Value = cookie_value;
            HttpContext.Current.Request.Cookies.Set(cookie);
        }
       
           
    </script>
    MultiUpload doesn't work with FireFox (my ver. is 31.0), I get 401 error when upload with 'Browse' button, it works fine with drag&drop.
    What am I doing wrong?
  2. #2
    Hi

    Unfortunatelly, it is known bug in Flash, SwfUpload will not work with Windows authentication
    https://code.google.com/p/swfupload/.../detail?id=236
  3. #3
    Ok, but I've changed authentication to 'forms' and now I get 302 error in the same place.
    My Logon.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Logon.aspx.cs" Inherits="Logon" %>
    
    <%@ Import Namespace="System.Web.Security" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthentication.RedirectFromLoginPage("test", false);
        }
      
    </script>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
      <title>Forms Authentication - Login</title>
    </head>
    <body>
      <form id="form1" runat="server">
      
      </form>
    </body>
    </html>
    New Web.config
    <?xml version="1.0"?>
    <configuration>
        <system.web>
          <httpHandlers>
            <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
          </httpHandlers>
    
          <httpModules>
            <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
          </httpModules>
    
          <pages>
            <controls>
              <add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" />
            </controls>
          </pages>
          <compilation debug="true" targetFramework="4.0" />
          
          <authorization>
            <deny users="?" />
          </authorization>
    
          <authentication mode="Forms">
            <forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH">
            </forms>
          </authentication>
    
        </system.web>
     
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
    
        <modules>
          <add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" />
        </modules>
    
        <handlers>
          <add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
        </handlers>
      </system.webServer>
      
    </configuration>
  4. #4
    302 status code means redirection
    It occurs because you always call 'FormsAuthentication.RedirectFromLoginPage' in page load
  5. #5
    Oh, it is login page (with FormsAuthentication.RedirectFromLoginPage)
    We will try to reproduce the issue.
  6. #6
    Somehow FireFox doesn't send ASP.NET's session and authentication's ids with cookies. It is why it breaks.

    At this point, I cannot understand why it happens.

    As a solution you could send those ids manually via a MultiUpload's PostParams and analyze in Global.asax, setting up the ids.
  7. #7
    We have found two approaches to overcome the issue.

    1. Sending session and authentication ids via a querystring by setting cookieless="UseUri".
    <forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH" cookieless="UseUri" />
    or

    2. Sending them manually via a MultiUpload's PostParams. Then they will be picked up by the code in Global.asax.
    <PostParams>
        <ext:Parameter Name="ASPSESSID" Value="<%# Session.SessionID %>" Mode="Value" AutoDataBind="true" />
        <ext:Parameter Name="AUTHID" Value="<%# Request.Cookies[FormsAuthentication.FormsCookieName] == null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>" Mode="Value" AutoDataBind="true" />
    </PostParams>
  8. #8
    Ok, it works. Thread can be closed, thanks.

Similar Threads

  1. MultiUpload does not work under panel
    By cwtsang1012 in forum 2.x Help
    Replies: 3
    Last Post: Jul 28, 2014, 1:29 PM
  2. [CLOSED] MultiUpload fails after publish
    By rsnead in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: May 21, 2014, 6:55 PM
  3. [CLOSED] Multiupload ErrorCode
    By vzx in forum 2.x Legacy Premium Help
    Replies: 9
    Last Post: Apr 30, 2014, 11:24 AM
  4. [CLOSED] MultiUpload Get All Files
    By vzx in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 27, 2013, 7:38 AM
  5. [CLOSED] Multiupload error code
    By Digital.Dynamics in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 23, 2013, 4:32 AM

Tags for this Thread

Posting Permissions