c# - ASP.NET-Core项目中的评估错误

标签 c# multithreading asp.net-core

我是ASP.NET的新手,并且将VS2017与.NET Core 2.0一起使用
这是ASP.NET-Core->没有授权的空项目。
我有以下问题:“函数评估需要运行所有线程”,并且在debugg mod中的Watch1中单击“立即评估”按钮时,VS响应“评估超时”。

这是我的C#代码,但现在全部

app.MapWhen(req => req.Request.Path.Value == "/cat/add",
                catAdd =>
                {                   
                    catAdd.Run( async (context) =>
                    {
                        if (context.Request.Method == HttpMethod.Get)
                        {
                            context.Response.Redirect("/cats-add-form.html");
                        }
                        else if (context.Request.Method == HttpMethod.Post)
                        {
                             var db = context.RequestServices.GetRequiredService<CatsDbContext>();

                             var formData = context.Request.Form;

                             var cat = new Cat
                             {
                                 Name = formData["Name"],
                                 Age = int.Parse(formData["Age"]),
                                 Breed = formData["Breed"],
                                 ImageUrl = formData["ImageUrl"]

                             };

                            db.Add(cat);

                            try
                            {
                                await db.SaveChangesAsync();

                                context.Response.Redirect("/");
                            }
                            catch
                            {
                                await context.Response.WriteAsync("<h2>Invalid cat data!</h2>");
                                await context.Response.WriteAsync(@"<href== ""/cat/add"">Back To The Form</a>");
                            }

                        }

                    });

                });

问题出在“formData”中

这是HTML
<h1>Add Cat</h1>

<form method="post" action="/cat/add">
    <label for="Name">Name:</label>
    <input type="text" name="Name" id="Name" />
    <br />
    <label for="Age">Age:</label>
    <input type="number" name="Age" />
    <br />
    <label for="Bread">Bread:</label>
    <input type="text" name="Bread" />
    <br />
    <label for="ImageUrl">ImageUrl:</label>
    <input type="url" name="ImageUrl" />
    <br />
    <input type="submit" value="Add Cat" />
</form>

我认为问题是:它不接受我的表单数据

最佳答案

我今天在asp.net core 2项目中也看到了这个问题。我认为可能存在与VS 2017调试器和asp.net core 2有关的错误。

当我将断点放在具有Request.Form的那一行之外时,一切正常。

请参阅此页面。 https://developercommunity.visualstudio.com/content/problem/146887/vs2017-v4-requestform-debug.html

关于c# - ASP.NET-Core项目中的评估错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48325012/

相关文章:

c# - 使用不工作的 Visual Studio 2019 自动导入

c# - session 在 ASP.NET Web 应用程序中未超时

c# - 使用 Word Interop 删除特定的换行符

java - ExecutorService超时而不阻塞主线程

c# - 在 .NET Core 世界中中止线程的替代方案?

asp.net-core - Gitlab CI : Skipping cache archiving due to empty cache key

c# - 将 json 序列化为对象 C#

python - 将args线程化到给定错误的许多参数?

c++ - 如何让 GNU GCC 类似地优化 OpenMP 线程

c# - 在 claim 中搜索