[asp.net]解決Cannot find the X.509 certificate using the following search criteria

  • 505
  • 0

[asp.net]解決Cannot find the X.509 certificate using the following search criteria

當伺服器的IIS應用程式集不允許使用較高的使用者權限執行的時候:(例如對方MIS不讓你使用較高權限來跑網站,不過這也是很常見的)
1.此時IIS的執行user大概就會是ApplicationPoolIdentity(除非你是用win xp,才會是NETWORK SERVICE)

2. 首先利用mmc指令打開憑證並選擇 電腦帳戶,下一步選擇 本機電腦(一般的憑證都是裝在 本機電腦 的選項)


3. 你將會發現你之前安裝的憑證,按下右鍵選擇 所有工作 ==> 管理私密金鑰
然後你會在 個人 ==> 憑證 的裡面發現加入使用者權限的畫面
下圖是已經成功把.NET v4.5 使用者加入權限的畫面
下一步會介紹怎麼加入權限


4. 把下列使用者加入,並給予完全控制權限
IIS AppPool\AppPoolName
AppPoolName請改為你的網站的應用程式集,像我的網站用的應用程式集是.NET v4.5(如下圖)
我的使用者就會是IIS AppPool\.NET v4.5
記得按下檢查名稱,然後才按下 確定


5. 最後回到config裡面,確認endpoint的設定是storeLocation="LocalMachine"
我這邊的情況是web.config
config檔案裡面可能會有很多地方要設定,別遺漏了

大概是這樣


參考資料:
How to set x509 Certificate private key access rights for AppPoolIdentity
http://geekswithblogs.net/SoftwareDoneRight/archive/2011/03/15/how-to-set-x509-certificate-private-key-access-rights-for.aspx
How to Grant IIS 7.5 access to a certificate in certificate store?
https://serverfault.com/questions/131046/how-to-grant-iis-7-5-access-to-a-certificate-in-certificate-store
Cannot find the X.509 certificate using the following search criteria 
https://stackoverflow.com/questions/31807672/cannot-find-the-x-509-certificate-using-the-following-search-criteria