すみません。Firefoxで次のプログラムを実行してファイルをアップロードしようとしていますが、
'../ajax/upload_mem_file.ashx'にセッション情報が渡りません。  
IE、Chromeだと渡ります。

このためFirefoxだと、「not login」のExceptionがThrowしてしまいます。

withCredentials: true にしているのにです。何がいけないかわかればご教授いただきたいです。

```

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="file_entry_ff.aspx.cs" Inherits="file_entry_ff" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
    <head>
        <link type="text/css" href="../../js/ui/css/jquery.ui.all.css" rel="stylesheet" />
        <link type="text/css" href="../../js/alert/jquery.alerts.css" rel="stylesheet" />
        <link type="text/css" href="../../js/flexgrid/flexigrid.css" rel="stylesheet" />
        <link type="text/css" href="../../js/thickbox/thickbox.css" rel="stylesheet" />
        <script type="text/javascript" src="../../js/jquery-1.8.0.min.js"></script>
        <script type="text/javascript" src="../../js/jquery-ui-1.8.23.custom.min.js"></script>
        <script type="text/javascript" src="../../js/jquery.alerts.js"></script>
        <script type="text/javascript" src="../../js/jquery.cookie.js"></script>
        <script type="text/javascript" src="../../js/thickbox.js"></script>
        <script type="text/javascript" src="../../js/jquery.maskedinput-1.3.min.js"></script>
        <script type="text/javascript" src="../../js/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../../js/jquery.ui.datepicker-ja.js"></script>
        <script type="text/javascript" src="../../js/flexigrid.pack.js"></script>
        <script type="text/javascript" src="../../js/messages_ja.js"></script>
        <link type="text/css" href="../../js/uploadify/css/uploadify.css" rel="stylesheet" />
        <script type="text/javascript" src="../../js/uploadify/jquery.uploadify.js"></script>
    </head>
    <body>
    <form id="form1" method="post" action="../ajax/upload_mem_file.ashx">
    <div id="wrapper">
        <div id="toolbar"></div>
        <%
            login_info lg = new login_info(this.Context);
            Session["shopcode"] = lg.login_shopcode;
            Session["File_Upload_Error"] = null;
         %>
        <script type = "text/javascript">
    
            var username = "username";
            var memo = "memo";
            var compcode = "compcode";
            var shopcode = "shopcode";
            var new_cnt = "new_cnt";
            var chg_cnt = "chg_cnt";
            var cancel_cnt = "cancel_cnt";
            var withdrawal_cnt = "withdrawal_cnt";
    
            $(document).ready(function() {
                $("#FileUpload1").fileUpload({
                    'uploader': '../../js/uploadify/uploader.swf',
                    'cancelImg': '../../js/uploadify/images/cancel.png',
                    'buttonText': 'Excel FILE',
                    'script': '../ajax/upload_mem_file.ashx',
                    'fileDesc': 'Excel Files',
                    'fileExt': '*.xls;*.xlsx',
                    'multi': false,
                    //'auto': true,
                    'sizeLimit': 4000000,
                    onComplete: function(evt, queueID, fileObj, response, data) {
                        var url = "../ajax/***.ashx
                        $("#result_view").attr("src", "");
                        $("#result_view").attr("src", url);
                        return false;
                    }
                })
                $('#FileUpload1').scriptData = {
                async: false,
                xhrFields: {
                    withCredentials: true
                    }
                };
            });
    
            function post() {
                $('#FileUpload1').fileUploadSettings('scriptData', '&amp;' + $('form1').serialize);
                $('#FileUpload1').fileUploadStart();
            }
    
            function fid(obj) {
                return document.getElementById(obj);
            }
    
            function onChanges(obj, msg) {
                if (msg != "") {
                    if ($("#" + obj).val() == "") {
                        alert(msg + '件数は必須入力です。');
                        fid("upload").style.display = "none";
                        return false;
                    } else if (!$("#" + obj).val().match(/^[0-9]+$/)) {
                        alert(msg + '件数は半角数字を入力して下さい。' + $("#" + obj).val());
                        fid("upload").style.display = "none";
                        return false;
                    } else {
                        if ($("#new_cnt").val() == "" || $("#chg_cnt").val() == "" || $("#cancel_cnt").val() == "" || $("#withdrawal_cnt").val() == "") {
                            fid("upload").style.display = "none";
                            return false;
                        }
                    }
                } else {
                    fid("upload").style.display = "none";
                    return false;
                }
                fid("upload").style.display = "block";
            }
    </script>
    <table cellspacing="0" class="input_table" style="width:500px">
    <tr>
        <td style="background-color:#7F99BE" colspan="2">
            ①　入力</td>
    </tr>
    <tr>
        <td colspan="2">
            <textarea id="memo" rows="2" cols="40"></textarea><br />
        </td>
    </tr>
    <tr>
        <th style="width:100px">
            １件数
        </th>
        <td>
            <input type="text" id="new_cnt" maxlength="4" class="cd" onchange="onChanges('new_cnt', '１')"/>
        </td>
    </tr>
    <tr>
        <th style="width:100px">
            ２件数
        </th>
        <td>
            <input type="text" id="chg_cnt" maxlength="4" class="cd" onchange="onChanges('chg_cnt', '２')"/>
        </td>
    </tr>
    <tr>
        <th style="width:100px">
            ３件数
        </th>
        <td>
            <input type="text" id="cancel_cnt" maxlength="4" class="cd" onchange="onChanges('cancel_cnt', '３')"/>
        </td>
    </tr>
    <tr>
        <th style="width:100px">
            ４件数
        </th>
        <td>
            <input type="text" id="withdrawal_cnt" maxlength="4" class="cd" onchange="onChanges('withdrawal_cnt', '４')"/>
        </td>
    </tr>
    <tr>
        <td style="background-color:#7F99BE" colspan="2">
            ②ファイル選択</td>
    </tr>
    <tr>
        <th style="width:100px">
            Excelファイル選択
        </th>
        <td>
    &nbsp;<input type="file" id="FileUpload1" onchange=""/>        
        </td>
    </tr>
    <tr>
        <td style="background-color:#7F99BE" colspan="2">
            ③　ファイルをシステムにアップロード</td>
    </tr>
    <tr>
        <th style="width:100px">
            &nbsp;
        </th>
        <td>
            「アップロード」ボタンを押してください。<br />
            <input type="button" value="アップロード" id="upload" class="btn" onclick="post()" />
        </td>
    </tr>
    </table>
    
    <input type="hidden" id="username" value="<%=lg.login_user_name %>" />
    <input type="hidden" id="compcode" value="<%=lg.login_compcode %>" />
    <input type="hidden" id="shopcode" value="<%=lg.login_shopcode %>" />
    <iframe id="result_view" src="../ajax/file_entry.ashx" scrolling="no" width="500" height="200" frameborder="0" style="border: 0;"></iframe>
    <script type="text/javascript">
        onChanges("", "");
    </script>
    </div>
    </form>
    </body>
    </html>
    
```

■upload_mem_file.ashx

```

    <%@ WebHandler Language="C#" Class="upload_mem_file" %>
    
    using System;
    using System.IO;
    using System.Web;
    
    public class upload_mem_file : IHttpHandler, 
    
    System.Web.SessionState.IRequiresSessionState
    {  
    
        public void ProcessRequest (HttpContext context) 
        {
    
            context.Response.ContentType = "text/plain";
            context.Response.Expires = -1;
            string temp_location = string.Empty;
            string save_location = string.Empty;
    
            try
            {
    
                // init
                context.Session["File_Upload_Error"] = null;
                // 転送データ取得
                HttpPostedFile postedFile = context.Request.Files["Filedata"];
                string compcode = (string)context.Session["compcode"];
                string shopcode = (string)context.Session["shopcode"];
    
                System.IO.File.AppendAllText("D:\\log.log", shopcode + "\r\n");
    
                login_info lg = new login_info(context);
                if (!lg.is_login)
                {
                    throw new Exception("not login");
                }
                string filename = compcode + "-" + shopcode + "-" + DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(postedFile.FileName);
    
    
    
                // save location
                temp_location = pdf_location(postedFile.FileName, "MEMBER_DATA_PATH");
                save_location = pdf_location(filename, "MEMBER_DATA_PATH");
    
                postedFile.SaveAs(temp_location);
                File.Copy(temp_location, save_location);
                File.Delete(temp_location);
    
                // session
                context.Session["File_Upload_PostedFile"] = postedFile.FileName;
                context.Session["File_Upload_File"] = filename;
                context.Session["File_Upload_save_location"] = save_location;
    
                // response            
                context.Response.StatusCode = 200;
                context.Response.Write("0");
            }
            catch (Exception ex)
            {
                context.Session["File_Upload_Error"] = ex.Message + ex.StackTrace + save_location;
                context.Response.Write("9");
            }                
        }
    
        public bool IsReusable 
        {
            get {
                return false;
            }
        }
    }
    
```
CC BY-SA 3.0
2015-12-09T09:42:29.813
19804
2015-12-10T10:33:00.100
2015-12-10T10:33:00.100
3061
13595
question
javascript c# jquery asp.net firefox
Firefox環境だとC#でSessionが取得できない
`async: false`が問題なようです。[jQuery
1.8から非推奨](http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings)となっています。

> Note that synchronous requests may temporarily lock the browser, disabling
> any actions while the request is active. **As of jQuery 1.8, the use
> of`async: false` with jqXHR (`$.Deferred`) is deprecated; you must use the
> success/error/complete callback options instead of the corresponding methods
> of the jqXHR object such as `jqXHR.done()` or the deprecated
> `jqXHR.success()`.**

英語版SOに[xhrFields.withCredentials will crash in Firefox if you're making
synchronous AJAX call](https://stackoverflow.com/questions/16041172/backbone-
js-wont-make-cross-host-requests#comment37730116_16043390)というコメントもありました。
CC BY-SA 3.0
2015-12-09T12:57:42.990
19816
2015-12-09T12:57:42.990
2017-05-23T12:38:55.307
-1
4236
19804
answer