Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 8c441bf

Browse files
author
NTaylorMullen
committed
Added a conditional AntiForgery.
1 parent 1e46bfe commit 8c441bf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
1616
public class FormTagHelper : TagHelper
1717
{
1818
private const string RouteAttributePrefix = "route-";
19+
private static readonly bool DefaultAntiForgeryBehavior = true;
1920

2021
[Activate]
2122
private ViewContext ViewContext { get; set; }
@@ -41,6 +42,12 @@ public class FormTagHelper : TagHelper
4142
/// </summary>
4243
public string Method { get; set; }
4344

45+
/// <summary>
46+
/// Whether the anti-forgery token should be generated. Defaults to <c>true</c>.
47+
/// </summary>
48+
[HtmlAttributeName("anti-forgery")]
49+
public bool? AntiForgery { get; set; }
50+
4451
/// <inheritdoc />
4552
/// <remarks>Does nothing if <see cref="Action"/> contains a '/'.</remarks>
4653
public override void Process(TagHelperContext context, TagHelperOutput output)
@@ -78,9 +85,11 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
7885

7986
output.Merge(tagBuilder);
8087

81-
// TODO: Make this behavior optional once https://github.com/aspnet/Razor/issues/121 is completed.
82-
var antiForgeryTag = Generator.GenerateAntiForgery(ViewContext);
83-
output.Content += antiForgeryTag.ToString(TagRenderMode.SelfClosing);
88+
if (AntiForgery ?? DefaultAntiForgeryBehavior)
89+
{
90+
var antiForgeryTag = Generator.GenerateAntiForgery(ViewContext);
91+
output.Content += antiForgeryTag.ToString(TagRenderMode.SelfClosing);
92+
}
8493
}
8594
}
8695

0 commit comments

Comments
 (0)