diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/AntiforgeryAuthTests.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/AntiforgeryAuthTests.cs index 9faad06136..02f791c7a7 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/AntiforgeryAuthTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/AntiforgeryAuthTests.cs @@ -51,5 +51,15 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } + + [Fact] + public async Task AntiforgeryOverridesIgnoreAntiforgery() + { + // Arrange & Act + var response = await Client.PostAsync("http://localhost/IgnoreAntiforgery/Index", content: null); + + // Assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } } } diff --git a/test/WebSites/SecurityWebSite/Controllers/AntiforgeryController.cs b/test/WebSites/SecurityWebSite/Controllers/AntiforgeryController.cs index 59c4b9de7e..24deaff657 100644 --- a/test/WebSites/SecurityWebSite/Controllers/AntiforgeryController.cs +++ b/test/WebSites/SecurityWebSite/Controllers/AntiforgeryController.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc; -namespace AjaxAntiForgeryValidation.Controllers +namespace SecurityWebSite.Controllers { [AutoValidateAntiforgeryToken] public class AntiforgeryController : Controller diff --git a/test/WebSites/SecurityWebSite/Controllers/IgnoreAntiforgeryController.cs b/test/WebSites/SecurityWebSite/Controllers/IgnoreAntiforgeryController.cs new file mode 100644 index 0000000000..64b8779679 --- /dev/null +++ b/test/WebSites/SecurityWebSite/Controllers/IgnoreAntiforgeryController.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Mvc; + +namespace SecurityWebSite.Controllers +{ + [IgnoreAntiforgeryToken] + public class IgnoreAntiforgeryController : Controller + { + [HttpPost] + [ValidateAntiForgeryToken] + public IActionResult Index() + { + return Content("Ok"); + } + } +}