【发布时间】:2020-09-16 19:08:06
【问题描述】:
我今天通过以下命令行安装了 Blazor WebAssembly 示例项目 (WeatherForecast):
dotnet new blazorwasm --hosted -o ProjectName
我在调试模式下通过 Visual Studio 2019 安装后直接启动了 SPA。浏览器是:Chrome。浏览器显示应用程序,但是当我选择导航菜单“获取数据”时,什么也没有发生。 Chrome 显示 1 个错误:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
System.NotSupportedException: The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'.
at System.Net.Http.Json.HttpContentJsonExtensions.ValidateContent (System.Net.Http.HttpContent content) <0x2e87f38 + 0x0009a> in <filename unknown>:0
at System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync[T] (System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e87d30 + 0x00006> in <filename unknown>:0
at System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsyncCore[T] (System.Threading.Tasks.Task`1[TResult] taskResponse, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken) <0x2e40838 + 0x0011c> in <filename unknown>:0
at BlazorIssue.Client.Pages.FetchData.OnInitializedAsync () [0x00033] in D:\Projects\BlazorIssue\Client\Pages\FetchData.razor:43
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2b8cb98 + 0x0013a> in <filename unknown>:0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x2dd8340 + 0x000b6> in <filename unknown>:0
Chrome 显示以下请求标头:
上下文信息:
- Chrome:V83.0.4103.61(64 位)
- Blazor:V3.2.0
- Visual Studio:V16.6.0
- DotNet V3.1.300
- DotNet SDK:V3.1.300
这很奇怪,因为这个示例项目的全新安装昨天没有问题。
【问题讨论】:
-
你能告诉我们
dotnet --version和dotnet --list-sdks的输出吗?我们应该看到 3.1.300 吗?另外请确认各种 AspNetCore Blazor 参考的版本是什么,应该是Version="3.2.0" -
我刚刚完成了同一个应用程序的设置。 WeatherForecast GET 应该是
content-type: application/json; charset=utf-8而你的是text/html- 我怀疑它可能会返回一个错误页面。尝试直接在浏览器中运行https://localhost:44325/WeatherForecast?
标签: asp.net asp.net-web-api blazor blazor-client-side blazor-webassembly