我正在尝试在 /app 下部署我的 Blazor 服务器应用程序,它是 IIS 中的一个子应用程序。我在网上的几个地方读到我需要设置以下内容:
Startup.cs | app.UsePathBase("/app")
Run Code Online (Sandbox Code Playgroud)
和
_Host.cshtml | <base href="~/app/" />
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我收到以下错误:
blazor.server.js:15 [2020-05-26T16:16:11.796Z] Error: The circuit failed to initialize.
e.log @ blazor.server.js:15
blazor.server.js:1 [2020-05-26T16:16:11.798Z] Information: Connection disconnected.
blazor.server.js:1 Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
at e.connectionClosed (blazor.server.js:1)
at e.connection.onclose (blazor.server.js:1)
at e.stopConnection (blazor.server.js:1)
at e.transport.onclose (blazor.server.js:1)
at e.close (blazor.server.js:1)
at e.stop (blazor.server.js:1)
at e.<anonymous> (blazor.server.js:1)
at blazor.server.js:1
at Object.next (blazor.server.js:1)
at a (blazor.server.js:1)
Run Code Online (Sandbox Code Playgroud)
如果我更改为(不带斜杠)
_Host.cshtml | <base …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的软件中创建一个基本的用户管理模块,并且我已按照本指南创建该模块:
我想这是微软推荐的最佳实践。但是,我不明白以下内容:
c# user-management identityserver4 blazor blazor-webassembly
我使用以下代码为我的 Blazor WebAssembly 项目生成 C# 客户端 API。
using (HttpResponseMessage response = client.GetAsync("https://localhost:5001/swagger/v1/swagger.json").Result)
{
using (HttpContent contentapi = response.Content)
{
var json = contentapi.ReadAsStringAsync().Result;
var document = await OpenApiDocument.FromJsonAsync(json);
var settings = new CSharpClientGeneratorSettings
{
ClassName = "Client",
CSharpGeneratorSettings =
{
Namespace = "MyProjectClient",
}
};
var generator = new CSharpClientGenerator(document, settings);
var code = generator.GenerateFile();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想从 Newtonsoft.Json 迁移到 System.Text.Json,因为我在一些较大的 API 请求中遇到非常慢的反序列化(长达几秒)。
我在网上找到了一些迁移指南,但我想继续使用上面的 NSwag 工具链来生成我的 API 客户端,因为否则它工作得非常好。有谁知道如何告诉 NSwag 工具链使用 System.Text.Json 而不是 Newtonsoft.Json?
我正在使用 ASP.NET Core WebAPI,我想为名为“Item”的对象执行 CRUD。我正在使用 EF Core 来处理 SQL 数据库,并且有两个模型来代表我的对象。
我的 HTTP GET one 和 HTTP GET much 方法的工作方式如下
获取 ItemRepository 实例
获取一个或多个ItemEntity
使用 AutoMapper将其映射到ItemDto这在我的构造函数中初始化,例如
m_itemDtoMapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap<ItemEntity, ItemDto>()));
Run Code Online (Sandbox Code Playgroud)
在我的 WebAPI 方法中,我使用以下行将其映射到 ItemDto(对于 GET 许多情况):
var itemDtos = m_itemDtoMapper.Map<IEnumerable<ItemEntity>, ICollection<ItemDto>>(items);
Run Code Online (Sandbox Code Playgroud)
这很有效,并且 AutoMapper 非常强大。我现在的问题是: