-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Html.AntiForgeryToken() writes nothing on second call #5005
Comments
Workaround: save generated token to variable and write this variable multiple times. @{
var token = Html.AntiForgeryToken();
}
<form id="form-one">
@token
</form>
<form id="form-two">
@token
</form> Crosspost: http://stackoverflow.com/questions/37511452 |
@justdmitry this looks like what might happen if the In your @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers or @addTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers |
@dougbu you're right, I have no any tag helpers in my code. But IMHO it seems a little wrong that behavior of one feature ( |
@justdmitry your approach might work though more code to detect when other features are not being used seems odd. Another approach would be to register the A few other features depend on a per- On the other hand, ASP.NET Core MVC actually creates unique On the links between MVC features, that's a tough row to hoe. For example, tag and HTML helpers generate names the model binding system understands. |
After a quick chat here, realize the correct fix is to change |
Correct way is to detect that other features are being used and enable additional intelligence only in that case. Otherwise, silly generate more and more hidden inputs if requested. Registering some more tag helpers by default is not a good idea - that's extra fat for brilliant reborn/newborn framework. You added new comment while I was writing this one... Yes, it looks like a good solution. |
Cleared Investigate label and assignee since investigation is done. |
Much appreciated @rynowak |
- #5005 - also add `FormContext` doc comments
- #5005 - also add `FormContext` doc comments
- #5005 - also add `FormContext` doc comments
- #5005 - also add `FormContext` doc comments
- #5005 - also add `FormContext` doc comments
When having several forms in one Razor view - antiforgery token is written only to first one.
View:
Generated html:
But second form should (expected) also include hidden
input
with (same?) token!Checked on 1.0.0 RTM bits.
The text was updated successfully, but these errors were encountered: