在OnConnected方法中,客户端将以其名称添加到组(该组包含所有客户端ID),然后将其名称添加到列表(如果不存在)。
static List<string> onlineClients = new List<string>(); // list of clients names
public override Task OnConnected()
{
Groups.Add(Context.ConnectionId, Context.User.Identity.Name);
if (!onlineClients.Exists(x => x == Context.User.Identity.Name))
{
onlineClients.Add(Context.User.Identity.Name);
}
return base.OnConnected();
}
Run Code Online (Sandbox Code Playgroud)
在OnDisconnected方法中,我试图测试该组是否为空以从列表中删除元素。但是,删除最后一个连接后,组不为空。
public override Task OnDisconnected(bool stopCalled)
{
if (stopCalled)
{
// We know that Stop() was called on the client,
// and the connection shut down gracefully.
Groups.Remove(Context.ConnectionId, Context.User.Identity.Name);
if (Clients.Group(Context.User.Identity.Name) == null)
{
onlineClients.Remove(Context.User.Identity.Name);
}
}
return base.OnDisconnected(stopCalled);
}
Run Code Online (Sandbox Code Playgroud)
我可以检查空组吗?
我有一个使用 adsense api 的报告应用程序。我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync 进行身份验证。当我在本地运行它时,它工作正常,权限请求窗口打开,在我授予访问权限后一切正常我的问题是当我将它部署到生产服务器并在 IIS 上运行时,GoogleWebAuthorizationBroker.AuthorizeAsync 永远挂起。我的猜测是它试图打开服务器上的授权窗口,但无法做到这一点。我没有编写这个实现,它已经投入生产一段时间了,它曾经工作得很好。我不确定发生了什么以及是否发生了变化,但现在不起作用。我四处冲浪并尝试了不同的方法 bot 都没有奏效。当我尝试使用 GoogleAuthorizationCodeFlow 并将 AccessType 设置为“离线”时 并且使用提供的 URI 它仍然不起作用。我也尝试使用服务帐户,但后来我了解到它们不支持 Adsense。下面是代码示例
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = ConfigurationManager.AppSettings["AdSenseClientId"],
ClientSecret = ConfigurationManager.AppSettings["AdSenseClientSecret"]
},
new string[] { AdSenseService.Scope.Adsense },
"xxxxxxxx@gmail.com",
CancellationToken.None).Result;
// Create the service.
adSenseService = new AdSenseService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "My API Project"
});
var adClientRequest = adSenseService.Adclients.List();
var adClientResponse = adClientRequest.Execute();
Run Code Online (Sandbox Code Playgroud)
对于解决此问题的示例代码,我会非常满意。我看到了这篇文章(ASP.NET MVC5 Google APIs GoogleWebAuthorizationBroker.AuthorizeAsync 在本地工作但未部署到 IIS),但它没有代码示例,也没有帮助我。
先感谢您。
我有一个具有相同CancellationTokenSource.
我希望当前线程等待所有任务完成或任务被取消。
Task.WaitAll(tasks.ToArray(), searchCencellationTokenSource.Token);
System.Console.WriteLine("Done !");
Run Code Online (Sandbox Code Playgroud)
即使当前线程处于等待状态,这些任务也可能被另一个任务取消。这是正常行为。
然而,当当前线程处于等待状态并且另一个任务取消任务时,WaitAll 抛出CancellationTokenSource一条消息:“操作被取消。”。
我知道它被取消了,我是故意这样做的。我只是希望它在任务取消或完成后继续执行下一个代码,而不抛出异常。
我知道我可以用 try & catch 来包装这段代码,但是抛出异常是一个繁重的操作,我不希望它发生在这样的正常行为上。
我只是在提交表单后尝试让Google Invisible ReCaptcha工作.我的问题是,ReCaptcha不是看不见的,看起来像是"旧的"重新出现了.我不明白为什么.我的网站密钥是无形的recaptcha.请帮我.
首先,我正在加载API:
<script src='https://www.google.com/recaptcha/api.js?render=explicit&onload=onScriptLoad' async defer></script>
Run Code Online (Sandbox Code Playgroud)
我的表单看起来像这样:
<form method="post" id="contact-form-face" class="clearfix" onsubmit="return false">
<input type="text" required name="name" value="name" onFocus="if (this.value == 'name') this.value = '';" onBlur="if (this.value == '') this.value = 'name';" />
<button type="submit" id="sendButton" data-size="invisible" class="g-recaptcha contact_btn" onclick="onSubmitBtnClick()" value="send" >send</button>
</form>
Run Code Online (Sandbox Code Playgroud)
JS:
window.onScriptLoad = function () {
// this callback will be called by recapcha/api.js once its loaded. If we used
// render=explicit as param in script src, then we can explicitly render reCaptcha at this …Run Code Online (Sandbox Code Playgroud) 我正在制作一个简单的asp.net应用程序,它显示可以根据几个不同的参数进行过滤的数据.因此,当前选择的不同过滤器需要保存在某处.我是.NET的新手,我想知道保存这些信息的最佳方法.我注意到一位同事将Request.QueryString与Sessions字典结合使用.页面加载时这样的东西:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["Category"] != null &&
Request.QueryString["Value"] != null)
{
string Category = Request.QueryString["Category"];
string CategoryValue = Request.QueryString["Value"];
// selectedFacets is the server side dictionary
selectedFacets.Add(Category, CategoryValue);
}
}
Run Code Online (Sandbox Code Playgroud)
当用户按下网页上的按钮更新URL时,会更改此处的QueryString.
我的问题是,为什么在我们使用它时,甚至根本不需要使用QueryString来保存值服务器端呢?不仅仅是让按钮成为asp控制器更容易,例如:
protected void exampleCatexampleVal_Button_onClick(object sender, EventArgs e)
{
selectedFacets.Add(exampleCat, exampleVal);
}
Run Code Online (Sandbox Code Playgroud)
类似的业务继续使用Sessions字典:它只是用于将一堆值保存到服务器上的变量,那么为什么要首先使用它呢?我确信这是有充分理由的,但是现在他们看起来似乎过于复杂.谢谢!
我ListBox在我的XAML中使用了ItemTemplate.在ItemTemplate我放置的图像里面.
<ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel x:Name="itmTempPanel" IsItemsHost="True" ItemWidth="60" ItemHeight="60" Width="{Binding ElementName=lstFilesDropped, Path=Width}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
...
<Image>
<Image.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" To="71" Duration="0:0:0.3" />
<DoubleAnimation Storyboard.TargetName="itmTempPanel" Storyboard.TargetProperty="Height" To="71" Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
当鼠标进入图像时,我想在该图像高度和WrapPanel我在其中定义的图像高度上开始故事板ItemsPanelTemplate.
当鼠标进入此图像时,我得到以下异常:"'itmTempPanel'名称在'System.Windows.Controls.Image'的名称范围内找不到."
如何从开始故事板的元素更改其他元素属性.
谢谢您的帮助 !!
我正在我的 jsp 页面中呈现 google recaptcha 小部件,并在我提交表单时以编程方式调用我的 java 脚本中的挑战。
<script type="text/javascript" id="recaptcha-response">
var siteKey = $('#recaptchasitekey').first().text();
var onloadCallback = function() {
grecaptcha.render('recaptcha_element', {
'sitekey' : siteKey,
'callback' : correctCaptcha,
'data-bind' : "qoActionTemplate"
},true);
};
var correctCaptcha = function(response) {
return response;
};
</script>
<div class="g-recaptcha" id="recaptcha_element" data-size="invisible" ></div>
<script src="http://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
<script type="text/template" id="recaptchaUrl">
Run Code Online (Sandbox Code Playgroud)
这是我调用挑战的 java 脚本代码。
executeRecaptcha : function() {
grecaptcha.execute();
captcha.token = grecaptcha.getResponse();
if (captcha.token == null || captcha.token == '') {
grecaptcha.reset();
grecaptcha.execute();
}
return captcha.token;
}, …Run Code Online (Sandbox Code Playgroud) 我需要用Javascript计算这个div的高度.
当我写这个脚本时:
function getMainDivHeight() {
var num = document.getElementById('up_container').style.height;
return num;
}
Run Code Online (Sandbox Code Playgroud)
这个脚本返回 auto
改变后我需要div的高度.
谢谢 !!!
我最近接触了 Entity Framework 6缓存机制。正如我们可能从本文中得出的那样,它以一级方式进行。
我们的系统使用 EF 6(代码优先)MemoryCache来提高性能。
我们使用的主要原因MemoryCache是因为我们需要对每个页面请求执行密集查询。我们在每个页面请求上执行此查询 x3 次(在最坏的情况下),因为有客户端回调。
我想知道如果MemoryCacheEF 6 已经使用了一种机制,我们是否还需要使用该机制。
值得一提的是,我们没有使用任何特殊的缓存功能或缓存依赖项。只是一个简单MemoryCache的超时。
我有以下ListBox,其中ContentControl为DataTemplate:
<ListBox x:Name="lstActionConfigs" ItemsSource="{Binding Path=AllActionConfigList}" SelectedItem="{Binding Path=ListSelectedItem, Mode=TwoWay}" HorizontalContentAlignment="Stretch" Grid.Row="3" Margin="0,0,0,5">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type helper:ItemDetails}">
<ContentControl Template="{StaticResource ResourceKey=actionDetailsListItemTemplate}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<i:Interaction.Behaviors>
<behaviours:BringIntoViewBehaviour CustomIsSelected="{Binding Path=IsSelected, Mode=TwoWay}"/>
</i:Interaction.Behaviors>
</ContentControl>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
每个有界实例都具有“ IsSelected”属性,该属性通过以下方式通知UI INotifyPropertyChanged:
public bool IsSelected
{
get { return isSelected; }
set
{
isSelected = value;
notify("IsSelected");
}
}
Run Code Online (Sandbox Code Playgroud)
我建立了一个自定义行为,以查看将IsSelectedProperty更改为true的元素,如下所示:
public class BringIntoViewBehaviour : Behavior<FrameworkElement>
{
public bool CustomIsSelected
{
get { return (bool)GetValue(CustomIsSelectedProperty); }
set { SetValue(CustomIsSelectedProperty, value); }
}
public static readonly DependencyProperty CustomIsSelectedProperty =
DependencyProperty.Register("CustomIsSelected", …Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×3
javascript ×3
jquery ×2
recaptcha ×2
wpf ×2
.net ×1
adsense-api ×1
ajax ×1
caching ×1
captcha ×1
data-binding ×1
html ×1
invisible ×1
listbox ×1
multitasking ×1
mvvm ×1
query-string ×1
session ×1
signalr ×1
signalr-hub ×1
triggers ×1
xaml ×1