Azure App Service“无法找到服务证书”

时间:2017-06-27 22:44:08

标签: azure certificate azure-web-sites wif acs

我有一个使用ACS登录的Azure应用服务,如果它有帮助的话,它是一个MVC 5站点。

它需要一个证书,让我们说指纹是 AF47AF47AF47AF47AF47AF47AF47AF47AF47AF47

我是通过门户网站上传的:enter image description here

然后我添加了应用程序设置>应用程序设置WEBSITE_LOAD_CERTIFICATES / *: enter image description here

在本地工作(当然) - 当我在Azure上加载时,我得到:

  

无法找到服务证书:   AF47AF47AF47AF47AF47AF47AF47AF47AF47AF47在我的商店上   CurrentUser HandlingInstanceID:74429bcf-4e02-4e28-a261-329bf831f7ce   发生了类型'System.ArgumentNullException'的异常   抓住。   -------------------------------------------------- -------------------------- 06/27/2017 22:21:44类型:System.ArgumentNullException,mscorlib,   Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089   消息:值不能为空。

(堆栈跟踪不可用)

知道我错过了什么吗?我已经尝试在我的 Application_Start()中加载证书,但没有运气 - 如果有人想要,我可以发布该代码。

1 个答案:

答案 0 :(得分:2)

您似乎希望将证书上传到Azure应用服务网络应用中的证书集合,并将其从您网站的个人证书存储中的MVC应用程序中使用,我上传证书并添加名为WEBSITE_LOAD_CERTIFICATES的应用设置,我可以使用以下代码访问我的应用程序中的证书,请参阅它。

var thumbprint = "xxxxxxxxxxxxxx";

X509Certificate2 retVal = null;

X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);

X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

if (certCollection.Count > 0)
{
    retVal = certCollection[0];
}

certStore.Close();

remote debug web app并且按预期工作。

enter image description here

此外,this article解释了使用Azure App Services中的证书的详细步骤,请参阅它。