小编Rev*_*ven的帖子

为什么WindowsIdentity类在.NET Core中不可见

在VisualStudio 2017 .NET Core 2.0控制台应用程序中具有以下代码

using System;
using System.Security.Principal;

namespace smallTests
{
    class Program
    {
        static void Main(string[] args)
        {
            var identity = WindowsIdentity.GetCurrent();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么我收到错误:

The name 'WindowsIdentity' does not exist in the current context    
Run Code Online (Sandbox Code Playgroud)

如果我可以在.Net Core docs中的.NET Core 2.0库中看到这个类?

相同的代码适用于.NET控制台应用.

[编辑]

@Will @JohnnyL评论说我没有提及System.Security.Principal.Windows.dll,这是真的.

但我很好奇为什么它不起作用,因为在.NET 4.6.1项目中(类WindowsIdentity可见)我也没有System.Security.Principal.Windows.dll具体提到这一点.但是我引用了System.dll.

我一直认为它像命名空间层次结构一样工作.例如,当我提到

System.Security.Principal.dll

我可以使用里面的课程

System.Security.Principal.Windows.dll.

我错了吗?

System.Security.Principal.dll手动添加到.NetCore解决方案但它仍然无效.

[EDIT2]

@Will非常感谢你们很多关于它帮助我的主题.我试图弄明白是WindowsIdentity与Core兼容,看来请注意:

在声明区域的这个apisof.net中,我可以看到WindowsIdentity在,.Net Core 2.0 System.Security.Principal.Windows, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a 但我没有System.Security.Principal.Windows.dll引用,我应该添加吗?如果是的话从哪里来? …

.net c# .net-core

9
推荐指数
1
解决办法
6344
查看次数

请求内容意外结束 Kestrel ASP.NET Core

我在两个 WebApi 之间发送大(20GB)文件时遇到问题。

WebAPI1 编写于ASP.NET 4.6

WebAPI2 编写于ASP.NET Core 2.0

当我通过 Postman 将此文件发送到 WebAPI2 时,整个文件都会被发送。但是,当我尝试将文件从 WebAPI1 发送到 WebAPI2 时,它失败了(不过我可以发送 7GB 之类的文件)。

在发送 20GB 文件期间,我在 WebAPI2 中收到错误:

Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected
 end of request content.
   at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeCompl
etion.ThrowFailed()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.GetR
esult(ReadResult& result)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.Micr
osoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwai
ter.GetResult()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableB
ufferAwaitable.GetResult()
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.<ReadAs
ync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestStream.
<ReadAsyncInternal>d__21.MoveNext()
--- End of stack trace …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

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

从WebAPI发送大文件。内容长度为0

我正在尝试将大文件(GB)从一个WebAPI(.NET Core)发送到另一个WebApi(.Net Core)。

我已经设法将较小的文件作为Multipart Request的一部分发送,就像上一篇文章在这里:link

要发送更大的文件,我需要(我认为)将此文件作为StreamContent发送,但是我在接收请求的API中获得Content length = 0。

在此处输入图片说明 即使我正在发送(用于测试)较小的文件(10 Mb),也会出现问题。

客户端代码:

    [HttpPost("UploadFiles")]
    public async Task<IActionResult> Post(IFormFile file)
    {
        var filePath = Path.GetTempFileName();

        using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
        {
            await file.CopyToAsync(stream);
            using (var formDataContent = new MultipartFormDataContent())
            {
                using (var httpClient = new HttpClient())
                {
                    formDataContent.Add(CreateFileContent(stream, "myfile.test", "application/octet-stream"));

                    var response = await httpClient.PostAsync(
                        "http://localhost:56595/home/upload",
                        formDataContent);

                    return Json(response);
                }
            }
        }
    }

    internal static StreamContent CreateFileContent(Stream stream, string fileName, string contentType)
    {
        var fileContent = new StreamContent(stream); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-web-api asp.net-core

5
推荐指数
1
解决办法
2092
查看次数

标签 统计

c# ×3

asp.net-core ×2

.net ×1

.net-core ×1

asp.net ×1

asp.net-web-api ×1