如果在Visual Studio中打开了代码窗口,如何快速让Solution Navigator或Solution Explorer显示当前文件是否已打开?
我正在构建一个受ACS保护的Azure WCF服务,该服务要求客户端通过证书进行身份验证.
我希望客户端(和服务器)从X509Store而不是从文件系统加载他们各自的密码证书.
我正在使用此代码:
private static X509Certificate2 GetCertificate(string thumbprint)
{
var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
thumbprint, false);
certStore.Close();
if (certCollection.Count == 0)
{
throw new System.Security.SecurityException(string.Format(CultureInfo.InvariantCulture, "No certificate was found for thumbprint {0}", thumbprint));
}
return certCollection[0];
}
Run Code Online (Sandbox Code Playgroud)
问题是,它没有加载验证所需的私钥.我试图将return语句修改为:
return new X509Certificate2(certCollection[0].Export(X509ContentType.Pfx, "password"));
Run Code Online (Sandbox Code Playgroud)
但是,这会因CryptographicException"Spcecified网络密码不正确"而失败.
编辑: 如果您没有传递密码参数,.Export()方法可以正常工作.
对此有何帮助?
我正在设置一个Mock,如下所示.它被传递到目标的构造函数中.目标具有Decrypt方法,该方法在目标的生命周期内被调用两次.每次调用Decrypt方法时,都会在安装程序中处置"新建"的证书.但是,当第二次调用Decrypt对象时,我在尝试解密时获得了ObjectDisposed方法.如果我用调用GetCertificate()的ICertificateHelperAdapter的伪实现替换这个Mock,那么第二次调用Decrypt就可以正常工作.
我推断当我使用Mock时,它不会在后续调用GetCertificate时返回对象的新实例.这是设计的吗?
private Mock<ICertificateHelperAdapter> GetCertificateHelperAdapter()
{
Mock<ICertificateHelperAdapter> certificateHelper = new Mock<ICertificateHelperAdapter>();
certificateHelper.Setup(
ch => ch.GetCertificate(CertStoreName.My, StoreLocation.LocalMachine, It.IsAny<string>())).Returns(this.GetCertificate()).Verifiable();
return certificateHelper;
}
private X509Certificate2 GetCertificate()
{
return new X509Certificate2(Environment.CurrentDirectory + "\\" + "azureconfig.pfx", "dingos");
}
Run Code Online (Sandbox Code Playgroud) 如何在谓词中使用TryParse方法?TryParse需要out参数.在下面的示例中,我想调用TryParse来确定x是否可以转换为整数.我真的不关心out参数 - 我只是想让它编译.
string[] nums = num.Split('.');
PexAssume.TrueForAll(nums, x => int.TryParse(x, out (int)0));
Run Code Online (Sandbox Code Playgroud) 我正在评估Sharepoint(不是MOSS)与ASP.NET作为我们团队即将推出的解决方案的开发平台.我们将为各种环境中的广泛(我们希望)部署开发解决方案.我正在确定用于评估每个平台选择的优缺点的类别.我选择了适用于我们的解决方案要求的类别,这将影响开发人员/测试人员的工作效率.任何人都可以想到适合比较的任何其他类别吗?任何人都可以提供有关任何类别的两个平台体验的任何细节吗?
其他一些信息,我们有两个短的时间来发布一些东西,所以我们在说话时优先考虑功能.我们将Sharepoint看作是一种快速解决问题的方法,同时利用UI框架实现基本UI,安全性以及列表和文档库的存储.
冗余/复制/备份/恢复支持