AppDomain.CurrentDomain.BaseDirectory gives me the bin directory in server-side blazor. But when I go to client-side wasm this same call return "/". Just a root. How do I carry a file in the root of the client app and then use it in the client? Thanks!
-
2You must understand that WASM applications fully run at the client machine. They are boxed/containered by the browser, i.e. there's no way you can simply access local files (that would be a GREAT security risk). The answer to your question depends on what you want to achieve, so please provide more details.– JHBonariusCommented Feb 23, 2021 at 9:05
-
Yes, thank you, I do understand that it runs client side and that it would be a security risk to allow full out access on the local resources. However, this should be a decision for the user, in my opinion. Afterall, it is their resource. Most things that provide value also create vulnerability. We seem very slow to adopt this change. Thank you!– ToddCommented Feb 23, 2021 at 14:56
-
No, the whole tendency is going in the opposite direction. Applications are actually becoming more "containerized" over the years. Users usually don't want to be bothered with decisions on giving access to resources. And they usually make bad decisions (like sharing data with Facebook through WhatsApp) which they later regret.– JHBonariusCommented Feb 23, 2021 at 16:36
-
I am not talking about containerization. I'm talking about giving the user more control...and that has been the tendency. The browser allows for more and more, NOT less and less. And some day, the browser will allow for access to more of the OS. It is necessary for the survival of the browser. Because, if it doesn't, something else will.– ToddCommented Feb 24, 2021 at 17:11
Add a comment
|
2 Answers
Have a look at Assembly.GetManifestResourceStream.
Here's a stackoverflow post discussing on how to use it.
Your workaround using another service returning the resource works for applications with internet access, but is not an option in an offline scenario. In my case, I simply needed a font file and embedding the file into the assembly worked just fine.
-
1In my scenario I am using WebDriver to automate browser tasks. So being online is necessary. Thank you for your contribution. I am sure it will be helpful for someone who comes across this in the future, and for that, we thank you.– ToddCommented Aug 26, 2021 at 18:16
It seems as if it is not possible. To work around, I will be creating a service that runs on the host.