AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Data Protection configuration: executing Provision-AutoGenKeys.ps1 error

Open t0xicDen opened this issue 10 years ago • 5 comments

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.

t0xicDen avatar Sep 23 '16 14:09 t0xicDen

Yup, we should add a note with the required PowerShell version

danroth27 avatar Sep 23 '16 18:09 danroth27

Add a note requires PS 4 or higher.

Rick-Anderson avatar Sep 23 '16 18:09 Rick-Anderson

This error also occurs when running in a nano server. Should this be updated to use Get-Acl and Set-Acl cmdlets instead?

johnwc avatar May 18 '17 18:05 johnwc

@blowdart

danroth27 avatar May 19 '17 05:05 danroth27

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.

Rick-Anderson avatar Nov 22 '17 21:11 Rick-Anderson