简体   繁体   中英

Evaluation error in ASP.NET-Core Project

I am new in ASP.NET and use VS2017 with .NET Core 2.0 This is ASP.NET-Core -> Empty project with no authorization. I have the following problem: "The function evaluation requires all threads to run" and when click button "evaluate now" in Watch1 in debugg mod, VS response "Evaluation timed out".

This is my C# code but now all

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>");
                            }

                        }

                    });

                });

The problem is in "formData"

This is 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>

I think the problem is: it doesn't take my form data

I also saw this issue in my asp.net core 2 project today. I think there might be a bug related to VS 2017 debugger and asp.net core 2.

When I put my breakpoint beyond that line that has Request.Form, everything works fine.

See this page. https://developercommunity.visualstudio.com/content/problem/146887/vs2017-v4-requestform-debug.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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