C# 在Web服务中找不到Windows Azure管理证书
我想使用Windows Azure管理API以编程方式扩展我的Web服务。首先我试着拿到我的管理证书 我使用makecert.exe创建了一个新的自签名证书。它被描述了 方法将调试消息写入表存储器。 最后,我在表中只找到以下条目:C# 在Web服务中找不到Windows Azure管理证书,c#,.net,azure,configuration,certificate,C#,.net,Azure,Configuration,Certificate,我想使用Windows Azure管理API以编程方式扩展我的Web服务。首先我试着拿到我的管理证书 我使用makecert.exe创建了一个新的自签名证书。它被描述了 方法将调试消息写入表存储器。 最后,我在表中只找到以下条目: "Error: No certificate found containing thumbprint " + certThumbprint 那么我的代码有什么问题吗?所以你在门户网站上传了你的证书。这意味着证书可用于向服务管理API进行身份验证 现在,如果您希望在以
"Error: No certificate found containing thumbprint " + certThumbprint
那么我的代码有什么问题吗?所以你在门户网站上传了你的证书。这意味着证书可用于向服务管理API进行身份验证 现在,如果您希望在以Web/Worker角色托管的WCF服务/Web服务中使用此证书,您还需要在云服务中上载该证书: 然后,您需要打开Web/Worker角色的设置,并通过指定位置、商店名称和指纹在此处添加新证书:
如果您重新部署应用程序,证书将可用,并且您的WCF服务将能够使用它(如果服务有足够的权限访问它)。因此您将证书上载到门户中。这意味着证书可用于向服务管理API进行身份验证 现在,如果您希望在以Web/Worker角色托管的WCF服务/Web服务中使用此证书,您还需要在云服务中上载该证书: 然后,您需要打开Web/Worker角色的设置,并通过指定位置、商店名称和指纹在此处添加新证书:
如果重新部署应用程序,证书将可用,并且您的WCF服务将能够使用它(如果该服务有足够的权限访问它)。如何从部署在azure中的Web服务访问该文件?在我看来,这是一个当地的节目好吧,我周末试试这个。谢谢您还需要更改行X509Store certStore=new X509Store(StoreName.My,StoreLocation.CurrentUser);要指向LocalMachine而不是CurrentUserName,如何从部署在azure中的Web服务访问该文件?在我看来,这是一个当地的节目好吧,我周末试试这个。谢谢您还需要更改行X509Store certStore=new X509Store(StoreName.My,StoreLocation.CurrentUser);指向LocalMachine而不是CurrentUser
private X509Certificate2 GetX509Certificate2()
{
// The thumbprint value of the management certificate.
// You must replace the string with the thumbprint of a
// management certificate associated with your subscription.
string certThumbprint = "mythumprint...";
// Create a reference to the My certificate store.
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
// Try to open the store.
try
{
certStore.Open(OpenFlags.ReadOnly);
}
catch (Exception e)
{
if (e is CryptographicException)
{
Console.WriteLine("Error: The store is unreadable.");
debugTable.persist("Error: The store is unreadable.");
}
else if (e is SecurityException)
{
Console.WriteLine("Error: You don't have the required permission.");
debugTable.persist("Error: You don't have the required permission.");
}
else if (e is ArgumentException)
{
Console.WriteLine("Error: Invalid values in the store.");
debugTable.persist("Error: Invalid values in the store.");
}
else
{
debugTable.persist("Something got wrong with certificate");
return null;
}
}
// Find the certificate that matches the thumbprint.
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbprint, false);
certStore.Close();
// Check to see if our certificate was added to the collection. If no, throw an error, if yes, create a certificate using it.
if (0 == certCollection.Count)
{
Console.WriteLine("Error: No certificate found containing thumbprint " + certThumbprint);
debugTable.persist("Error: No certificate found containing thumbprint " + certThumbprint);
return null;
}
debugTable.persist("found cert");
// Create an X509Certificate2 object using our matching certificate.
X509Certificate2 certificate = certCollection[0];
return certificate;
}
"Error: No certificate found containing thumbprint " + certThumbprint