简体   繁体   English

在 mvc 中上传文件时,Visual Studio 调试会立即停止吗?

[英]Visual Studio debugging stop immediately on file upload in mvc?

So I'm trying to get into .NET Core MVC using Visual Studio 2019 Enterprise.所以我正在尝试使用 Visual Studio 2019 Enterprise 进入 .NET Core MVC。

I tried to follow a fairly simple example from Microsofts own documentation .我试图按照 Microsoft 自己的文档中的一个相当简单的示例进行操作。 After setting up the code, I have the template project that they give you with MVC.设置代码后,我有了他们为您提供的带有 MVC 的模板项目。 So on the "About" page I have the following controller class AboutController.cs with the method found on Microsofts website:因此,在“关于”页面上,我有以下 controller class AboutController.cs以及在 Microsoft 网站上找到的方法:

[HttpPost("UploadFiles")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
    long size = files.Sum(f => f.Length);
    string filePath = Path.GetTempFileName();

    if (files.Count > 0)
    {
        IFormFile file = files[0];
        if (file.Length > 0)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
        }
    }

    return View();
}

The only "big" difference is that I return the view, not an "Ok" because I'm not really interested in that.唯一的“大”区别是我返回视图,而不是“确定”,因为我对此并不真正感兴趣。 I want to modify the view I'm looking at not go to a completely new view (maybe I'm misunderstanding how MVC works?).我想将我正在查看的视图 not go 修改为一个全新的视图(也许我误解了 MVC 的工作原理?)。

Now my HTML looks like this:现在我的 HTML 看起来像这样:

<form method="post" enctype="multipart/form-data" asp-controller="About" asp-action="Post">
    <div class="form-group">
        <div class="col-md-10">
            <p>Upload one image using this form:</p>
            <input type="file" name="files">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-10">
            <input type="submit" value="Upload">
        </div>
    </div>
</form>

This produces the form, also as seen in their documentation linked earlier.这会生成表单,也如之前链接的文档中所示。 When I click the "Browse" button to find a picture, it works fine and when I click "Open" so I can upload it, the Visual Studio debugger stops running immediately.当我单击“浏览”按钮查找图片时,它工作正常,当我单击“打开”以便上传它时,Visual Studio 调试器立即停止运行。 No error anywhere that I can see.我能看到的任何地方都没有错误。

Any idea what causes this behaviour?知道是什么导致了这种行为吗?

Update 1更新 1

It appears that just calling return View();似乎只是调用 return View(); exhibits the same behaviour and Nuget says it's AspNetCore.Mvc 2.1.1表现出相同的行为,Nuget 表示它是 AspNetCore.Mvc 2.1.1

Update 2更新 2

Turns out the debugger does not work in this particular instance with the browser called "Brave" which is a chromium browser that I use (which If forgot to mention)事实证明调试器在这个特定实例中无法使用名为“Brave”的浏览器,这是我使用的铬浏览器(如果忘记提及)

This behavior in specific has been attributed to a browser problem and not Visual Studio in general.这种行为具体归因于浏览器问题,而不是一般的 Visual Studio。 As per this article and this article, this behavior was generally observed when using browsers like Brave in this case and Yandex.根据这篇文章和这篇文章,在这种情况下使用 Brave 和 Yandex 等浏览器时,通常会观察到这种行为。 Sometimes even Chrome shows this behavior but it is not consistent (at least that is what I have observed).有时甚至 Chrome 也会显示这种行为,但并不一致(至少这是我观察到的)。

A possible solution would be changing your browser type to use ideal browsers like Chrome, Firefox or Edge.一个可能的解决方案是更改您的浏览器类型以使用理想的浏览器,例如 Chrome、Firefox 或 Edge。

I have the issue with Visual Studio 2017 Professional Edition (4.8)我有 Visual Studio 2017 专业版 (4.8) 的问题

And I am using Microsoft Edge Version 94.0.992.47.我使用的是 Microsoft Edge 版本 94.0.992.47。

So what I did is I restarted browser and Visual Studio and everything works fine afterwards.所以我所做的是重新启动浏览器和 Visual Studio,之后一切正常。 It's strange but restarting sometime works.这很奇怪,但有时重新启动会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM