jeudi 28 mars 2019

Reading server-side files using Blazor

I have a project based on the Blazor sample with a .Client, .Server and .Shared projects. I have a textfile data.txt on the server that I want to be able to read/write using standard StreamReader / System.IO.File methods. Since Blazor runs in a sandbox I guess I can't access the entire filesystem as I would in a normal windows app? I've placed the file in the wwwroot directory, and I can even access the file from the client if a enter url/data.txt in the browser so the file gets served, which I don't want to alow, but trying to read that file as such:

var file = File.ReadAllText("data.txt");

Results in the error:

WASM: [System.IO.FileNotFoundException] Could not find file "/data.txt"

How can I read server-side files and keep them hidden from the client?




Aucun commentaire:

Enregistrer un commentaire