我已经将.NET Core2.2 API 发布到IISv.10,由于某种原因它响应 500!
我试过
我将不胜感激你的建议。谢谢
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
launchSettings.json文件:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5694",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"x": {
"commandName": "Project",
"applicationUrl": "http://localhost:5694",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Linux 上的 VS Code 中创建一个 Angular 项目。我想使用框架版本 2.2(已安装),但我还为另一个需要它的项目安装了 3.0 的预览版。
当我运行时dotnet new angular,它默认使用 3.0。好吧,我去手动编辑 csproj。问题是,存在依赖性,特别是
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.0.0-preview4-19216-03" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我以为我可以更改两个部门的版本,但我错了。3.0之前的版本似乎NewtonsoftJson不存在。
此时,我不确定最好的方法是什么。我不想四处寻找并手动添加正确的依赖项。我真的希望使用 dotnet cli 来创建我的项目。
那么如何指定框架版本呢dotnet new?如果不能,我该如何通过 dotnet CLI 创建一个可用的 angular.js 项目?
我最近在现有的基于 .NET Core 的应用程序中将 elasticsearch 升级到 7.1,将 NEST 升级到版本 7.0 alpha 2。
我正在生成搜索请求,其中使用 SortField 类来指定要执行排序的字段。
它在 Elasticsearch 和 NEST 的 6.X 版本上运行良好,但现在版本升级后,我在使用 SortField 类时遇到错误。
var sortField = new SortField();
错误消息是“找不到类型或命名空间名称‘SortField’”
请帮助我解决问题或让我知道实现它的替代方法。
供参考。我使用 SortField 而不是 SortDescriptor 来指定 UnmappedType。
谢谢
我的问题是,当我在 .Net CORE 中对 Signalr 集线器进行单元测试时,获取 context.connection ID 值插入我的方法之一。我的方法在我的测试类中如下所示:
[Fact]
public async Task TestWorkstationCreation()
{
Mock<IHubCallerClients<IWorkstation>> mockClients = new Mock<IHubCallerClients<IWorkstation>>();
Mock<IWorkstation> mockClientProxy = new Mock<IWorkstation>();
mockClients.Setup(clients => clients.All).Returns(mockClientProxy.Object);
_workstationHub.Clients = mockClients.Object;
await _workstationHub.RegisterWorkstation("WKS16", "Ready", new Dictionary<string, string> {{"OS", "Windows 10"}, {"Exam", "GRE, TOEFL"}});
mockClientProxy.Verify(c => c.WorkstationRegistered(It.IsAny<WorkstationDataModel>(), It.IsAny<string>()), Times.AtLeastOnce);
}
Run Code Online (Sandbox Code Playgroud)
在我的集线器类中,这是方法:
public async Task RegisterWorkstation(string id, string status, Dictionary<string, string> capabilities)
{
_logger.LogInformation(
"Registering a Workstation with id: {id}, status: {status}, and capabilities: {capabilities}",
id, status, string.Join(",", capabilities));
var workstationAdded = …Run Code Online (Sandbox Code Playgroud) 当我运行我的角度应用程序时,我得到了一个 CORS,尽管我已经在我的 .NET Core 应用程序中启用了它,但常规的 http 请求似乎工作正常,只是 SignalR 遇到了问题。任何建议将不胜感激。提前致谢。
\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:5001/api/chat/negotiate. (Reason: expected \xe2\x80\x98true\xe2\x80\x99 in CORS header \xe2\x80\x98Access-Control-Allow-Credentials\xe2\x80\x99).\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:5001/api/chat/negotiate. (Reason: CORS request did not succeed).\n\n[2019-07-06T19:34:25.061Z] Warning: Error from HTTP request. 0: . Utils.js:206\n[2019-07-06T19:34:25.065Z] Error: Failed to complete negotiation with the server: Error Utils.js:203\n[2019-07-06T19:34:25.070Z] Error: Failed to start the connection: Error Utils.js:203\nError while establishing connection :( …Run Code Online (Sandbox Code Playgroud) 我正在使用 fetch 调用 POST 控制器操作,但在控制器中,主体似乎为空。
这是我的获取代码片段 - 这是在 .net core Vue 项目中。这是一个打字稿文件。
var data = JSON.stringify(this.newProduct);
console.log(data)
fetch('api/Product/AddNewProduct', {
method: 'POST',
body: data,
headers: {
'Content-Type': 'application/json'
}
}).then(res => res.json())
.then(response => console.log('Success:', JSON.stringify(response)))
.catch(error => console.error('Error:', error));
Run Code Online (Sandbox Code Playgroud)
这是我在 Firefox 中看到的请求(和负载):
但在我的 .net core 后端中,当 API 受到攻击时,我似乎无法获取请求体或请求中任何内容的值。
[HttpPost("[action]")]
public IActionResult AddNewProduct([FromBody] string body)
{
Product newProduct;
try
{
/*Added the below snippet for testing, not sure if actually necessary */
using (var reader = new StreamReader(Request.Body))
{
var requestBody …Run Code Online (Sandbox Code Playgroud) 我正在使用 xUnit 和 Moq 编写测试用例。
目前我正在为遥测类编写测试用例。
public class TelemetryClientMock : ITelemetryClientMock
{
public string key { get; set; } //I want to mock key variable.
private TelemetryClient telemetry;
public TelemetryClientMock( )
{
telemetry = new TelemetryClient() { InstrumentationKey = key };
}
public void TrackException(Exception exceptionInstance, IDictionary<string, string> properties = null)
{
telemetry.TrackException(exceptionInstance, properties);
}
public void TrackEvent(string eventLog)
{
telemetry.TrackEvent(eventLog);
}
}
Run Code Online (Sandbox Code Playgroud)
在测试类中,我如何模拟关键变量。我曾经为模拟方法编写以下代码。
[Fact]
public void TrackException_Success()
{
Exception ex=null;
IDictionary<string, string> dict = null;
var reader = new …Run Code Online (Sandbox Code Playgroud) 我编译下面的代码以获得引导面板但没有成功
@page "/test"
<h3>test</h3>
<div class="panel panel-primary">
<div class="panel-heading">Panel with panel-primary class</div>
<div class="panel-body">Panel Content</div>
</div>
@code {
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.main.cs 是
wwwroot 文件夹如下所示
索引.html
我知道如何取消任务,但找不到有关如何向 ValueTask 方法添加取消的任何信息。通常我会取消这样的任务:
public async Task<int> Foo(
CancellationToken cancellationToken)
{
TaskCompletionSource<int> tcsCancel =
new TaskCompletionSource<int>();
cancellationToken.Register(() =>
{
tcsCancel.TrySetCanceled();
});
Task<int> task = LongOperation();
var completedTask = await Task.WhenAny(
tcsCancel.Task,
task).ConfigureAwait(false);
return await completedTask.ConfigureAwait(false);
}
Run Code Online (Sandbox Code Playgroud)
或者像这样:
if (cancellationToken.IsCancellationRequested)
return Task.FromCanceled<int>(cancellationToken);
Run Code Online (Sandbox Code Playgroud)
事实是,ValueTask 既没有 FromCanceled 也没有 WhenAny。我是不是应该做...
cancellationToken.ThrowIfCancellationRequested();
Run Code Online (Sandbox Code Playgroud) 所以我有一个场景,我必须并行执行多个任务,我有一个具有继承自 a 的泛型类型的类,它将负责执行单个任务。对于每个任务,我想要一个新实例来执行给定的任务。目标是拥有一批工人。
Worker<T>:BackgroundService
Run Code Online (Sandbox Code Playgroud)
在启动中我添加如下:
services.AddTransient(typeof(Worker<>));
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我向 ServiceProvider 请求新实例时,返回的实例总是不同的?
.net-core ×10
c# ×7
asp.net-core ×3
.net ×2
angular ×2
signalr ×2
xunit ×2
asp.net-mvc ×1
async-await ×1
blazor ×1
cancellation ×1
cors ×1
iis ×1
json ×1
moq ×1
nest ×1
razor ×1
transient ×1
vue.js ×1