标签: .net-core

在 IIS 上启动 .NET Core Web API 时出错:“应用程序正在 IIS 进程内运行,但未配置为使用 IIS 服务器”

我已经将.NET Core2.2 API 发布到IISv.10,由于某种原因它响应 500!

我试过

  • stdoutLogEnabled="true" (未生成日志文件)
  • app.UseDeveloperExceptionPage(无)
  • dotnet.exe x.dll 其中 x 是项目名称(表示:未配置侦听端点。绑定到http://localhost:5000)然后它可以在 5000 而不是 IIS 上的指定端口上完美运行

我将不胜感激你的建议。谢谢

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)

c# iis .net-core asp.net-core

0
推荐指数
1
解决办法
1万
查看次数

使用 dotnet new Angular 指定框架版本

我正在尝试在 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 visual-studio-code angular

0
推荐指数
1
解决办法
863
查看次数

NEST 7.0 alpha 2 中的 SortField 与 Elasticsearch 7.1

我最近在现有的基于 .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 c# elasticsearch nest .net-core

0
推荐指数
1
解决办法
644
查看次数

模拟 Context.ConnectionId 以进行单元测试 Signalr .NetCore 消息中心

我的问题是,当我在 .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)

xunit signalr .net-core asp.net-core asp.net-core-signalr

0
推荐指数
1
解决办法
2313
查看次数

SignalR CORS 同源政策?

当我运行我的角度应用程序时,我得到了一个 CORS,尽管我已经在我的 .NET Core 应用程序中启用了它,但常规的 http 请求似乎工作正常,只是 SignalR 遇到了问题。任何建议将不胜感激。提前致谢。

\n\n
Cross-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)

c# cors signalr .net-core angular

0
推荐指数
1
解决办法
2301
查看次数

控制器中的请求正文为空?

我正在使用 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)

c# asp.net-mvc json vue.js .net-core

0
推荐指数
1
解决办法
1万
查看次数

如何模拟类变量

我正在使用 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)

.net c# moq xunit .net-core

0
推荐指数
1
解决办法
3769
查看次数

为什么 Bootstrap 面板在 Blazor 客户端中不起作用?

我编译下面的代码以获得引导面板但没有成功

在此输入图像描述

@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

在此输入图像描述

razor .net-core blazor

0
推荐指数
1
解决办法
2078
查看次数

如何取消 ValueTask&lt;T&gt;

我知道如何取消任务,但找不到有关如何向 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)

c# task-parallel-library cancellation async-await .net-core

0
推荐指数
1
解决办法
805
查看次数

瞬态BackgroundService,返回的实例总是不同?

所以我有一个场景,我必须并行执行多个任务,我有一个具有继承自 a 的泛型类型的类它将负责执行单个任务。对于每个任务,我想要一个新实例来执行给定的任务。目标是拥有一批工人。

Worker<T>:BackgroundService
Run Code Online (Sandbox Code Playgroud)

在启动中我添加如下:

services.AddTransient(typeof(Worker<>));
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我向 ServiceProvider 请求实例时,返回的实例总是不同的?

c# transient background-service .net-core asp.net-core

0
推荐指数
1
解决办法
1749
查看次数