简体   繁体   中英

How to extract values from user input form via custom middleware?

I tried to find thoes values with debugger in HttpContext but it seems like it's more complicated than just Dictionary(key,value)

app.Use(async (context, next) =>
{
    foreach (var item in context.???)
    {
        Console.WriteLine('{item.Key}':'{item.Value}'");
    }
    await next.Invoke();
});

eg

Sample form:

<input type="text" name="FirstName" />
<input type="text" name="Age" />

Expected console output:

'FirstName':'John'
'Age':'123'

The place to go for form data is context.Request.Form. If you want query string data parsed out, it would be context.Request.Query...but the form data is what you need.

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