Reading a file inside wwwroot in Blazor Web Assembly ASP.NET Core hosted

Viewed 304

When creating a new Blazor Web Assembly solution from Visual Studio 2019 Preview (keep ASP.NET Core hosted unchecked), we have the possibility to perform a GetFromJsonAsync directly from a file located inside the wwwroot.

protected override async Task OnInitializedAsync()
{
    forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

When creating a new Blazor Web Assembly solution from Visual Studio 2019 Preview (with ASP.NET Core hosted checked), we have the possibility to perform a GetFromJsonAsync by calling an action from our controller WeatherForecastController.

protected override async Task OnInitializedAsync()
{
    forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
}

My question is: and what if in this second scenario (ASP.NET Core hosted) I would like to get data from a file located inside my wwwroot ? Is this not possible ? Security concern ?

Thanks.

1 Answers

what if in ASP.NET Core hosted I would like to get data from a file located inside my wwwroot ?

When you try it you will see that that just works. Those two ways of using HttpClient are not mutually exclusive.

Related