title: Using Swagger with ASP.NET Boilerplate returns 400 Bad Request with POST, PUT and Delete operations. Logs indicate a problem with anti-forgery token
body: <p>I am new to ASP.NET Boilerplate and I tried creating my first Application Service using a simple Entity.</p>
  
  <p>Here's the Entity:</p>
  
  <pre><code>public class Category : Entity
  {
      public string Name { get; set; }
      public string ImageUrl { get; set; }
  }
  </code></pre>
  
  <p>Domain Service:</p>
  
  <pre><code>public class CategoryManager : DomainService, ICategoryManager
  {
      private readonly IRepository&lt;Category&gt; _categoryRepository;
  
      public CategoryManager(IRepository&lt;Category&gt; categoryRepository)
      {
          _categoryRepository = categoryRepository;
      }
      public IEnumerable&lt;Category&gt; GetAll()
      {
          return _categoryRepository.GetAllList();
      }
  
      public Category GetById(int id)
      {
          return _categoryRepository.Get(id);
      }
  
      public Category Add(Category category)
      {
          return _categoryRepository.Insert(category);
      }
  
  
  }
  </code></pre>
  
  <p>Application Service:</p>
  
  <pre><code>public class CategoryAppService : ApplicationService, ICategoryAppService
  {
      private readonly ICategoryManager _categoryManager;
  
      public CategoryAppService(ICategoryManager categoryManager)
      {
          _categoryManager = categoryManager;
      }
  
  
      public ListResultDto&lt;CategoryDto&gt; GetAll(GetAllCategoriesInput input)
      {
          var categories = _categoryManager.GetAll();
  
          return new ListResultDto&lt;CategoryDto&gt;(ObjectMapper.Map&lt;List&lt;CategoryDto&gt;&gt;(categories));
      }
  
      public CategoryDto GetById(GetCategoryByIdInput input)
      {
          var category = _categoryManager.GetById(input.Id);
          return ObjectMapper.Map&lt;CategoryDto&gt;(category);
      }
  
      public CategoryDto Create([FromBody]CategoryDto input)
      {
          var category = _categoryManager.Add(ObjectMapper.Map&lt;Category&gt;(input));
  
          return ObjectMapper.Map&lt;CategoryDto&gt;(category);
      }
  
  
  }
  </code></pre>
  
  <p>When I try to access the Get endpoints using swagger, everything is working as expected. But, when I try accessing the other endpoints, it returns 400 undocumented error.</p>
  
  <p><a href="https://i.stack.imgur.com/SXEA9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SXEA9.png" alt="Example of Invoking &quot;Create&quot; endpoint using Swagger"></a></p>
  
  <p><a href="https://i.stack.imgur.com/GCO83.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GCO83.png" alt="Example response"></a></p>
  
  <p>Here's some info I found in the output window about the request made with swagger:</p>
  
  <pre><code>    SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
  SampleService.Web.Mvc&gt;       Request starting HTTP/1.1 POST http://localhost:62114/api/services/app/Category/Create application/json 86
  SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
  SampleService.Web.Mvc&gt;       Route matched with {area = "app", action = "Create", controller = "Category"}. Executing action SampleService.Categories.AppServices.CategoryAppService.Create (SampleService.Application)
  SampleService.Web.Mvc&gt; info: Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter[1]
  SampleService.Web.Mvc&gt;       Antiforgery token validation failed. The required antiforgery header value "X-XSRF-TOKEN" is not present.
  SampleService.Web.Mvc&gt; Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The required antiforgery header value "X-XSRF-TOKEN" is not present.
  SampleService.Web.Mvc&gt;    at Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery.ValidateRequestAsync(HttpContext httpContext)
  SampleService.Web.Mvc&gt;    at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ValidateAntiforgeryTokenAuthorizationFilter.OnAuthorizationAsync(AuthorizationFilterContext context)
  SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
  SampleService.Web.Mvc&gt;       Authorization failed for the request at filter 'Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter'.
  SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Mvc.StatusCodeResult[1]
  SampleService.Web.Mvc&gt;       Executing HttpStatusCodeResult, setting HTTP status code 400
  SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
  SampleService.Web.Mvc&gt;       Executed action SampleService.Categories.AppServices.CategoryAppService.Create (SampleService.Application) in 0.6744ms
  SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
  SampleService.Web.Mvc&gt;       Request finished in 9.4144ms 400 
  SampleService.Web.Mvc&gt; info: Microsoft.AspNetCore.Server.Kestrel[32]
  SampleService.Web.Mvc&gt;       Connection id "0HLGPB44TBNED", Request id "0HLGPB44TBNED:00000001": the application completed without reading the entire request body.
  </code></pre>
  
  <p>Please help if you can.</p>
  
  <p>Thanks in advance.</p>