Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 异步函数返回正确的数据,客户端为';t显示正确的数据_C#_Asp.net Mvc_Razor - Fatal编程技术网

C# 异步函数返回正确的数据,客户端为';t显示正确的数据

C# 异步函数返回正确的数据,客户端为';t显示正确的数据,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我正在与LiveChat API集成。 当客户登录到网站时,我们在控制器中读取他的数据,然后将模型发送回客户机,在那里进行渲染并发送到LiveChat,但发送的数据是随机的客户机。 我怀疑这是因为多线程操作。 以下是客户端代码: @model Forex.ApplicationUser @if (Request.IsAuthenticated) { <script type="text/javascript"> window.__lc =

我正在与LiveChat API集成。 当客户登录到网站时,我们在控制器中读取他的数据,然后将模型发送回客户机,在那里进行渲染并发送到LiveChat,但发送的数据是随机的客户机。 我怀疑这是因为多线程操作。 以下是客户端代码:

@model Forex.ApplicationUser

@if (Request.IsAuthenticated)
{
    <script type="text/javascript">
        window.__lc = window.__lc || {};
        window.__lc.license = 9761490;
        window.__lc.params = [
            { name: "CRM Account", value: "http://crm_aws_vpc/cmt/main.aspx?etn=contact&pagetype=entityrecord&id=@ViewBag.ContactId" },
            { name: "Main trading account", value: "@ViewBag.MainTpAccount" },
            { name: "First name", value: "@ViewBag.FirstName" },
            { name: "Last name", value: "@ViewBag.LastName" },
            { name: "Equity", value: "@ViewBag.Equity" },
            { name: "Bonus blocked", value: "@ViewBag.BonusBlocked" },
            { name: "Compliance level", value: "@(ViewBag.ComplianceLevel == null ? "No compliance level" : ViewBag.ComplianceLevel.ToString().Substring(ViewBag.ComplianceLevel.ToString().Length - 1, 1))"},
            { name: "Contact owner", value: "@ViewBag.ContactOwner" },
            { name: "FTD amount ", value: "@ViewBag.FTDAmount" },
            { name: "FTD date", value: "@ViewBag.FTDDate" },
            { name: "Language", value: "@ViewBag.Language" },
            { name: "Lead status", value: "@ViewBag.LeadStatus" },
            { name: "Lead subStatus", value: "@ViewBag.LeadSubStatus" },
            { name: "Net deposit", value: "@ViewBag.NetDeposit" },
            { name: "Total deposit", value: "@ViewBag.TotalDeposit" },
            { name: "Is profiling completed", value: "@ViewBag.IsProfilingCompleted" },
            { name: "Affiliate", value: "@ViewBag.Affiliate" }
        ];
        (function () {
            const lc = document.createElement('script');
            lc.type = 'text/javascript';
            lc.async = true;
            lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
            const s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(lc, s);
        })();
    </script>
}
else
{
    <script type="text/javascript">
        window.__lc = window.__lc || {};
        window.__lc.license = 9761490;
        (function () {
            const lc = document.createElement('script');
            lc.type = 'text/javascript';
            lc.async = true;
            lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
            const s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(lc, s);
        })();
    </script>
}
[ChildActionOnly]
    [OutputCacheModified(Duration = 60, SpecialName = CacheVaryByCustomFlags.MenuChange | CacheVaryByCustomFlags.IsAuthenticated | CacheVaryByCustomFlags.Culture)]
    public ActionResult LiveChatInc()
    {
        ApplicationUser user;
        if (User.Identity.IsAuthenticated)
        {
            if (Request.Cookies["TpAccount"] == null)
            {
                user = AsyncHelpers.RunSync(async () => await UserManager.FindByNameAsync(User.Identity.CurrentAccount().Login.ToString()));
                if (user?.IsCrmDataMerged == true)
                    return PartialView("_LiveChatInc", user);
            }
            else {
                user = AsyncHelpers.RunSync(async () => await UserManager.FindByNameAsync(Request.Cookies["TpAccount"].Value));
                if (user?.IsCrmDataMerged == true)
                    return PartialView("_LiveChatInc", user);
            }
        }
        return PartialView("_LiveChatInc");
    }
_LiveChatInc.cshtml是一个局部视图,加载到整个网站的所有页面上。 谢谢
Igal

这实际上取决于AsyncHelpers.RunSync正在做什么。