Data Protection configuration: executing Provision-AutoGenKeys.ps1 error
Introduction:
OS: Windows Server 2008 R2 Enterprise Service Pack 1
I was configuring DataProtection keys. In this article (https://docs.asp.net/en/latest/hosting/dataprotection.html) I read about that:
To automatically persist keys for an application hosted in IIS, you must create registry hives for each application pool. Use the Provisioning PowerShell script for each application pool you will be hosting ASP.NET Core applications under. This script will create a special registry key in the HKLM registry that is ACLed only to the worker process account. Keys are encrypted at rest using DPAPI.
Problem:
When I tried to execute script I got error in PowerShell:
Unable to find type [Microsoft.Win32.RegistryView]: make sure that the assembly containing this type is loaded.
Resolving:
After some time googling I came to a conclusion that this assemblies are included to .Net Framework 4.0. But PowerShell by default using .Net 4.0 starting from PowerShell 3.0. And Windows Server 2008 R2 by default has PowerShell 2.0. You can check your PowerShell version using $PSVersionTable.PSVersion command in PowerShell.
After Installing Windows Management Framework 4.0 (in my case) that includes PowerShell 4.0 script start working successfully.
Conclusion: I think you should add notes about minimal PowerShell version to this article.
Yup, we should add a note with the required PowerShell version
Add a note requires PS 4 or higher.
This error also occurs when running in a nano server. Should this be updated to use Get-Acl and Set-Acl cmdlets instead?
@blowdart
Looks like this has been updated.
1. Create a Data Protection Registry Hive
Data Protection keys used by ASP.NET applications are stored in registry hives external to the applications. To persist the keys for a given application, you must create a registry hive for the app's application pool.