我有一個ASP.NET Core應用程序託管在Azure虛擬機中的IIS中。我調用擴展方法來將它們保存到Azure中,但沒有任何內容存儲在那裏,應用程序似乎仍然使用本地密鑰。我按照這裏的例子:http://intellitect.com/staying-logged-across-azure-app-service-swap/。事實上,當我在控制檯應用程序中測試代碼時,持久性工作正常。但是,當我使用此代碼運行ASP.NET Core應用程序時,沒有任何事情會持續到Azure。任何想法爲什麼?不保留給Azure的數據保護密鑰
0
A
回答
1
我將上面的回答標記爲答案,因爲它是正確的並且是重要的一點。但是,對於這個問題的真正答案是關鍵數據不會因爲應用程序啓動並且您調用PersistKeysToAzureBlobStorage(或任何其他PersistToXXX方法)而持久。這只是爲了配置數據保護。你可以說這是「懶惰」。關鍵數據將與您的代碼一起生成或框架首先調用Protect/Unprotect,如下所示:
var protector = provider.CreateProtector("Some Purpose");
var enc = protector.Protect("Hello World");
...
protector.Unprotect(enc);
2
請檢查註冊MVC服務和DataProtection服務的順序。註冊DataProtection服務必須在註冊MVC服務之前。以下代碼供您參考。
// Add DataProtection Service
if (storageUrl != null && sasToken != null && containerName != null && applicationName != null && blobName != null)
{
// Create the new Storage URI
Uri storageUri = new Uri($"{storageUrl}{sasToken}");
//Create the blob client object.
CloudBlobClient blobClient = new CloudBlobClient(storageUri);
//Get a reference to a container to use for the sample code, and create it if it does not exist.
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExists();
services.AddDataProtection()
.SetApplicationName(applicationName)
.PersistKeysToAzureBlobStorage(container, blobName);
}
// Add framework services.
services.AddMvc();
相關問題
- 1. 保護SSH密鑰
- 2. 密碼/密鑰保護
- 3. 如何在Azure密鑰保管庫中保護Blob存儲訪問密鑰
- 4. swift3 - 如何保護密鑰
- 5. keytool如何保護密鑰?
- 6. 保護對稱密鑰
- 7. API密鑰保留爲空
- 8. 保護C#中的加密密鑰#
- 9. 保護祕密數據不受損害
- 10. 在android中保護你的api密鑰
- 11. 保護密鑰文件中的
- 12. Azure AD B2C中的密碼保護B2C
- 13. 保護用於客戶端處理的數據庫密鑰
- 14. 保護Graphite的數據:url密鑰或代理?
- 15. Azure網站上的數據保護/加密?
- 16. 保護與RSA密鑰的許可證密鑰
- 17. 刪除密鑰的值並保留密鑰
- 18. 遠程存儲密碼保護私鑰
- 19. Android密鑰庫如何受到保護?
- 20. 保護Google Maps JavaScript API密鑰
- 21. VBA:保護整張紙並保留範圍不受保護
- 22. 將AWS密鑰保留在github上
- 23. 保留的IP地址(經典)分配給SQL數據庫Azure
- 24. Azure密鑰保管庫瞭解
- 25. 保存德比數據的密鑰
- 26. Web服務API密鑰和Ajax - 保護密鑰
- 27. EnvelopedCms解密不適用於Azure密鑰保管庫
- 28. 密碼保護SQL數據庫文件
- 29. 加密和保護Android數據
- 30. 保護密碼字段在數據庫