1

I'm trying to use a local secrets.xml file but an error tells me that it can't be found.

I right-clicked on the project and selected 'Manage User Secrets, which created the GUID-named folder and file for me. That same GUID appears in the userSecretsId attribute as below...

<configBuilders>
  <builders>
    <add name="Secrets" optional="false" userSecretsId="[a GUID]" type="..." />
  </builders>
</configBuilders>

But at runtime an exception shows that the file cannot be found.

I then switched to using userSecretsFile and pasted a copy of the file to C:\tmp\secrets.xml. This worked.

So I then pasted the path of the auto-generated secrets.xml - i.e....

%APPDATA%\Microsoft\UserSecrets\<userSecretsId>\secrets.xml

...into the userSecretsFile attribute...

<add name="Secrets" optional="false" userSecretsFile="C:\Users\[my username]\AppData\Roaming\Microsoft\UserSecrets\946bd95c-42a4-45da-aad0-a7874c97fd64\secrets.xml" type="..." />

...and still an exception is thrown saying that the file can't be found.

I'm running Visual Studio 2019 with administrator privileges. Why does it appear to be prevented from accessing the file?

awj
  • 7,482
  • 10
  • 66
  • 120
  • Have you referred to https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1&tabs=windows? – Jim Xu May 13 '20 at 07:41
  • Oh yes, I certainly have. If you think I've missed anything in the docs then please point it out. – awj May 14 '20 at 19:28
  • Is that you use .Net Framework? – Jim Xu May 15 '20 at 01:03
  • Yes, .NET Framework v4.7.2. – awj May 15 '20 at 10:15
  • If you use Net framework, please refer to https://medium.com/@hammadarif/how-to-safely-manage-passwords-in-net-applications-a546a481c41c – Jim Xu May 18 '20 at 05:05
  • There's nothing in that Medium article which isn't in the docs. It just repeats the same steps using different words. It also repeats the steps that my OP describes. – awj May 19 '20 at 11:40

0 Answers0