dotnet / AspNetCore.Docs.Samples

Creative Commons Attribution 4.0 International
181 stars 151 forks source link

IForm post /2 #221

Closed Rick-Anderson closed 1 year ago

Rick-Anderson commented 1 year ago

EDIT UPDATE: Looks like I need to use an HTML form like this approach

Contributes to https://github.com/dotnet/AspNetCore.Docs/issues/30644

@bruno see Support for form files in new form binding

@brunolins16 When I test with postman, I get

System.InvalidOperationException: Endpoint HTTP: POST /upload contains anti-forgery 
metadata, but a middleware was not found that supports anti-forgery.
Configure your application startup by adding app.UseAntiforgery() in the application 
startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to 
app.UseAntiforgery() must go between them. Calls to app.UseAntiforgery() must be 
placed after calls to app.UseAuthentication() and app.UseAuthorization().

So when I add app.UseAntiforgery();, I get

System.InvalidOperationException: This form is being accessed with an invalid anti-
forgery token. Validate the `IAntiforgeryValidationFeature` on the request before reading 
from the form.
Rick-Anderson commented 1 year ago

@BrunoGuardia when I run your sample, I get the same results.

BrunoGuardia commented 1 year ago

@Rick-Anderson nice seeing you! but I guess you meant a different Bruno

Rick-Anderson commented 1 year ago

@Rick-Anderson nice seeing you! but I guess you meant a different Bruno

Sorry, I meant @brunolins16