我正在使用WIF(.net 4.5)和Azure Active目录进行身份验证.该网站将位于Azure上.
一切都在本地工作,但是当我把它放到azure上时我得到错误:
数据保护操作失败.这可能是由于没有为当前线程的用户上下文加载用户配置文件引起的,这可能是线程模拟时的情况.
我理解这是因为应用程序无法使用DAPI,因此我需要切换到使用MAC保护我的应用程序.
在本地我把它添加到我的webconfig: -
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</securityTokenHandlers>
Run Code Online (Sandbox Code Playgroud)
正如文档中所建议的,我添加了一个静态机器密钥,但我找不到关于密钥长度的任何建议 - 所以我假设256.
但是,此配置只会出现此错误:
[CryptographicException:加密操作期间发生错误.] System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func,Byte [] input)+115 System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Unprotect(Byte [] protectedData)+59 System.Web.Security.MachineKey.Unprotect(ICryptoServiceProvider cryptoServiceProvider,Byte [] protectedData,String []用途)+62 System.Web.Security.MachineKey.Unprotect(Byte [] protectedData,String []用途)+ 122 System.IdentityModel.Services.MachineKeyTransform.Decode(Byte [] encoded)+161 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte [] cookie,Boolean outbound)+123 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader) ,SecurityTokenResolver tokenResolver)+575 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte [] token,SecurityTokenResolver tokenResolver)+76 System.IdentityModel.Services.SessionAuthenticationMod ule.ReadSessionTokenFromCookie(Byte [] sessionCookie)+833 System.IdentityModel.Services.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken&sessionToken)+186 System.IdentityModel.Services.SessionAuthenticationModule.OnAuthenticateRequest(Object sender,EventArgs eventArgs)+210 System.Web.SyncEventExecutionStep. System.Web.HttpApplication.IExecutionStep.Execute()+ 136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+69
我删除了machinekey部分,因为我没有指定格式正确的密钥,但错误不会消失.
什么是战斗WIF!
我正在查看异步的某个示例代码,并注意到它实现方式的一些问题.在查看代码时,我想知道使用并行循环遍历列表是否更有效,而不是正常循环遍历列表.
据我所知,性能差异很小,两者都占用了每个处理器,两者都在相同的时间内完成.
这是第一种方式
var tasks= Client.GetClients().Select(async p => await p.Initialize());
Run Code Online (Sandbox Code Playgroud)
这是第二个
var tasks = Client.GetClients().AsParallel().Select(async p => await p.Initialize());
Run Code Online (Sandbox Code Playgroud)
假设两者之间没有区别,我是否正确?
完整的程序可以在下面找到
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
RunCode1();
Console.WriteLine("Here");
Console.ReadLine();
RunCode2();
Console.WriteLine("Here");
Console.ReadLine();
}
private async static void RunCode1()
{
Stopwatch myStopWatch = new Stopwatch();
myStopWatch.Start();
var tasks= Client.GetClients().Select(async p => await p.Initialize());
Task.WaitAll(tasks.ToArray());
Console.WriteLine("Time ellapsed(ms): " + myStopWatch.ElapsedMilliseconds);
myStopWatch.Stop();
}
private async …Run Code Online (Sandbox Code Playgroud) 我有几个需要状态的容器 - 我只会将比例设置为1,但我希望这样,无论他们在卷上启动哪个主机都会被共享.
我猜我需要使用网络安装来实现这一点(这很好),但我怎么用docker swarm 1.12配置音量呢?
我知道我可以使用docker volume create,我想我可能需要指定一个驱动程序,但我很难找到一个这样的例子!
我有一个带有需要服务的构造函数的视图模型.我正在使用GalaSoft的MvvmLight,它使用服务定位器将视图连接到视图模型.
SimpleIOC处理为viewmodels构造函数提供服务很好,但我不知何故需要使用来自数据源的数据填充我的viewmodel.我的Viewmodel看起来像这样: -
public class MainPageViewModel : ViewModelBase
{
private readonly GroupService _groupService;
private readonly GroupFactory _groupFactory;
private readonly ObservableCollection<GroupVM> _groupVms = new ObservableCollection<GroupVM>();
public MainPageViewModel(Domain.Services.GroupService groupService, VMFactories.GroupFactory groupFactory)
{
_groupService = groupService;
_groupFactory = groupFactory;
}
public async Task Init()
{
var groups = await _groupService.LoadGroups();
foreach (var group in groups)
{
GroupVms.Add(_groupFactory.Create(group));
}
}
public ObservableCollection<GroupVM> GroupVms { get { return _groupVms; } }
}
Run Code Online (Sandbox Code Playgroud)
不知何故,init方法需要被称为等待,但我不知道如何最好地做到这一点?我可以想到三个选择: -
我在以前的Windows 8商店项目中使用了选项3,但它感觉不对.任何建议都会非常感激!
谢谢
罗斯
design-patterns mvvm mvvm-light windows-phone-8 windows-store-apps
我正在尝试编写一个移动应用程序,它将从基于webapi rest的站点获取数据.
该站点应通过ACS保护(因为可以有多个身份提供者).
我的移动应用程序目前正在查询以下网址https://xx.accesscontrol.windows.net/v2/metadata/IdentityProviders.js?protocol=javascriptnotify&realm=http://xx.azurewebsites.net/&version=1.0获取清单IP.
然后,我允许用户选择IP,然后使用Web浏览器控件向我们显示登录信息.
一旦用户登录,我捕获响应并提取令牌,但现在我不确定我应该做什么.令牌看起来像这样: -
{"appliesTo":"http://****.azurewebsites.net/",
"context":null,
"created":1362069383,
"expires":1362072983,
"securityToken":"... a lot of text:-)",
"tokenType":"urn:ietf:params:oauth:token-type:jwt"}
Run Code Online (Sandbox Code Playgroud)
所以,我猜我应该采取securityToken部分并添加它的部分Authorization标头到get请求?
问题1是我应该如何附加令牌 - 我只是附加安全令牌位,还是我必须对该批次进行64位编码并再次将其作为授权标头附加?
问题2如何配置webapi来处理JWT?在我修改了ACS以发出JWT令牌之后,我安装了JWTSecurityTokenHandler,我仍然收到以下错误(这是使用被动身份验证):
JWT10310: Unable to validate signature. validationParameters.SigningTokenResolver type: 'System.IdentityModel.Tokens.IssuerTokenResolver', was unable to resolve key to a token.
The SecurityKeyIdentifier is:
'SecurityKeyIdentifier
(
IsReadOnly = False,
Count = 1,
Clause[0] = X509ThumbprintKeyIdentifierClause(Hash = 0x2FEE3EE96B019D4BA0C046124B77C652EEF768E5)
)
'. validationParameters.SigningToken was null.
Run Code Online (Sandbox Code Playgroud)
谢谢
罗斯
我无法在Windows 8上获取chrome来打开mailto链接.它们在IE中运行良好,如果mailto由网站(例如gmail)处理,它们在chrome中工作正常,但如果Outlook设置为处理uri,我无法使其工作.
还有其他人遇到过这个问题吗?
我有一个以以下方式分布在多个功能中的过程:
Http绑定功能将消息保存在队列中队列绑定功能处理该消息,然后将另一个消息放入队列中。最后,另一个函数处理该消息并将某些内容保存在数据库中。
我想要的是使应用程序见解可以理解原始请求的上下文,并能够在所有分布式函数调用中跟踪请求的流程,但是我似乎没有办法设置操作ID正确(我认为这最终是实现我的要求的“正确”方法)。
我可以设置父ID,但这只会阻止收集的数据完全显示在应用程序见解中。我使用以下代码设置父ID:
private static void UpdateTelemetryContext(TelemetryContext context, ExecutionContext functionContext, string id)
{
context.Operation.Id = functionContext.InvocationId.ToString();
context.Operation.ParentId = id;
context.Operation.Name = functionContext.FunctionName;
}
Run Code Online (Sandbox Code Playgroud)
我可以实现目标的唯一方法是将用户ID设置为所需的上下文ID(将所有操作链接在一起的东西),并将合成源设置为“功能”,因此至少我知道它不是真正的用户。
这是我用来实现此目的的代码:
private static void UpdateTelemetryContext(TelemetryContext context, ExecutionContext functionContext, string id)
{
context.Operation.Id = functionContext.InvocationId.ToString();
context.Operation.ParentId = functionContext.InvocationId.ToString();
context.Operation.Name = functionContext.FunctionName;
context.User.Id = id;
context.Operation.SyntheticSource = "Functions";
}
Run Code Online (Sandbox Code Playgroud)
现在,在应用程序洞察力内部,我可以单击“显示用户的时间轴”并一起查看功能组的所有执行,但这感觉很错误,因此必须有一种更好的方法来实现。
我有一个使用AnyEvent :: MQTT订阅消息队列的perl脚本.
在我想要它做的那一刻,当它收到消息时打印出来.我是perl的新手所以我正在使用它附带的演示代码,其中包含一些在STDIN上发布任何内容作为消息 - 这很好用,我可以看到收到的所有消息.
此代码如下所示
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent::MQTT;
my $mqtt = AnyEvent::MQTT->new;
my $cv = $mqtt->subscribe(topic => '/AlarmMode',
callback => sub {
my ($topic, $message) = @_;
print $topic, ' ', $message, "\n"
});
my $qos = $cv->recv; # subscribed, negotiated QoS == $qos
# publish line-by-line from file handle
$cv = $mqtt->publish(handle => \*STDIN,
topic => '/topic');
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我在评论后删除所有内容,publish line-by-line from file handle那么我的应用程序会在它运行后立即退出.
我已经尝试过包含一个睡眠时间为5秒的while循环,但这不起作用(应用程序只是看起来像挂了).
我知道我需要做一些事情来告诉应用程序只是为了保持活力和冷静,但我不知道那个命令是什么:-)
当要显示的集合为空时,我想显示一个文本块,上面写着"你没有数据".
我可以通过使用转换器轻松地将此工作用于页面加载,但由于在收集数据更改时不会收到通知,因此代码不起作用: -
TextBlock Visibility="{Binding Devices, Converter={StaticResource EmtpyListToVisibility}, Mode=OneWay}" Text="You have no devices added, please press the Add Device button on the application bar" TextWrapping="Wrap"></TextBlock>
<phone:LongListSelector Margin="0,12,0,0" ItemsSource="{Binding Devices, Mode=OneWay}" ItemTemplate="{StaticResource DeviceTemplate}" LayoutMode="List" VerticalAlignment="Top" >
</phone:LongListSelector>
Run Code Online (Sandbox Code Playgroud)
在Windows 8应用程序中,我添加了一个名为xxxHasRecords的属性,然后我订阅了Observable集合CollectionChanged事件并使用了属性通知,因此我的UI可以更新.我发现自己经常编写这段代码,只需要更好的方法来处理它!
谢谢
罗斯
我的ApplicationData.Current.LocalFolder文件夹中有一个图像列表.我想在Image控件中显示第一个图像.
在我的viewmodel类中,我有以下代码: -
StorageFolder folder = ApplicationData.Current.LocalFolder;
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
if (files.Count > 0)
{
vm.SelectedImage = files[0].Name;
}
Run Code Online (Sandbox Code Playgroud)
我的Xaml有以下代码:
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding SelectedImage, Mode=OneWay}" CreateOptions="BackgroundCreation"/>
</Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚传递正确的字符串以显示图像 - 任何帮助将不胜感激!
钽
罗斯
我有一个对象,其中包含在验证对象时检查的业务规则列表.
在类的顶部,我创建了BusinessRule类型的静态字段,如下所示: -
public class SyncFile : Waterstons.Patterns.Entities.BaseEntity<Guid>
{
public static BusinessRule NameRequiredRule = new BusinessRule("Name", "The audit file must have a name");
....
protected override void Validate()
{
if (Id == default(Guid))
{
AddBrokenRule(IdRequiredRule);
}
....
Run Code Online (Sandbox Code Playgroud)
这导致代码分析抱怨我不应该有公共字段,除非它们是const.我不确定我可以根据我如何使用它们将它们定义为const.
那么有更好的方法来解决这个问题吗?我应该将它们作为属性公开吗?
public static BusinessRule _nameRequiredRule = new BusinessRule("Name", "The audit file must have a name");
public static BusinessRule Test
{
get { return _nameRequiredRule; }
}
Run Code Online (Sandbox Code Playgroud)
或者有更好的方法来解决这个问题吗?
azure ×2
c# ×2
wif ×2
anyevent ×1
asp.net ×1
asynchronous ×1
azure-acs ×1
docker ×1
docker-swarm ×1
mqtt ×1
mvvm ×1
mvvm-light ×1
perl ×1
silverlight ×1
volume ×1
windows-8 ×1
xaml ×1