Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnasaki/4766bb22cd76c5e66754 to your computer and use it in GitHub Desktop.
Save nnasaki/4766bb22cd76c5e66754 to your computer and use it in GitHub Desktop.
Microsoft.WindowsAzure.Management Library を Azure Web Siteで動かそうとしたら、動きませんでした。
エラーメッセージ
System.Security.Cryptography.CryptographicException はユーザー コードによってハンドルされませんでした。
HResult=-2147024894
Message=The system cannot find the file specified.
Source=mscorlib
StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)
at managementforwebsite.Controllers.HomeController.About() in c:\Users\nnasaki\Documents\Visual Studio 2013\Projects\azuremanagement\managementforwebsite\Controllers\HomeController.cs:line 25
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e()
InnerException:
動かそうとしたサンプルコードはこれ。
`var credentials = new CertificateCloudCredentials` でExceptionが発生します。
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.WebSites;
using Microsoft.WindowsAzure.Management.WebSites.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace azuremanagement
{
class Program
{
static void Main(string[] args)
{
var subscriptionId = "xxxxx";
var base64Certificate = "xxxx";
var credentials = new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64Certificate)));
using (var client = new WebSiteManagementClient(credentials))
{
var spaces = client.WebSpaces.List();
foreach (var space in spaces)
{
Console.WriteLine("Space: {0}", space.Name);
var sites = client.WebSpaces.ListWebSites(space.Name, new WebSiteListParameters { PropertiesToInclude = { "Name" } });
foreach (var site in sites)
{
Console.WriteLine(" " + site.Name);
}
}
}
}
}
}
http://stackoverflow.com/questions/9951729/x509certificate-constructor-exception に
> Turns out there's a setting in the IIS Application Pool configuration (Application Pools > Advanced Settings) to load the user profile for the application pool identity user. When set to false, the key containers aren't accessible.
とあるので、アプリケーションプールの設定を変える必要があるのでWebSiteじゃ無理?
SiteExtensionsでなんとかなるんでしょうか?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment