Environment Variables/Persistent Values in OpenSilver
Dear Community -
I am trying to find a way to store and recall user credentials (such as an API key from a back-end or other user-critical data) when using an OpenSilver project, and haven't had much luck.
I was wondering if the community could offer an insight on this.
What I've tried (without success) :
- Environment Variables (Using System.Environment).
- User Secrets.
- Storing a file in the file system.
Thank you, kindly!
7 Replies
in what way is it not working?
the filesystem is definitely the way to go here
user secrets isn't writable
and env vars aren't a place to dump your stuff
The
Directory.GetCurrentDirectory()
method returns "/"
, and I think the file system resets itself every time you refresh the page. I can't find any evidence that this file system has access to the host hard drive.
Also, when I set the environment variable one time, it it returns as null when I launch it a second time.Oh, Silverlight app, derp
Can you call out to localstorage?
MDN Web Docs
Window: localStorage property - Web APIs | MDN
The localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.
NuGet won't let me install the packages from it. Anyway I've moved on from OpenSL for the time being. Will give Blazor a fair shot.
Check the samples here: https://opensilverdemos.azurewebsites.net/opensilvershowcase/release/?20240130#/Net_Framework. I hope that this page will be useful.
Thank you!