C# 异步函数返回正确的数据,客户端为';t显示正确的数据
我正在与LiveChat API集成。 当客户登录到网站时,我们在控制器中读取他的数据,然后将模型发送回客户机,在那里进行渲染并发送到LiveChat,但发送的数据是随机的客户机。 我怀疑这是因为多线程操作。 以下是客户端代码: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 =
@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正在做什么。