title: Asp net core Error 405 method not allowed on POST
body: <p>I have an asp net core application developed with .NET 5.</p>
  <p>In this application, there is a controller (ACSController) that manages responses from an Identity Provider. The <strong>controller</strong> <strong>is the follow</strong>:</p>
  <pre><code>public class ACSController : Controller
  {
      private readonly IRequestRepository _requestRepository;
      private readonly IHttpClientFactory _httpClientFactory;
      private readonly IIdpRepository _idpRepository;
      private readonly IResponseRepository _responseRepository;
  
      private readonly AppSessionViewModel _session;
  
      public ACSController(IRequestRepository requestRepository, IHttpClientFactory httpClientFactory,
          IIdpRepository idpRepository, IResponseRepository responseRepository, AppSessionViewModel session)
      {
          _requestRepository = requestRepository;
          _httpClientFactory = httpClientFactory;
          _idpRepository = idpRepository;
          _responseRepository = responseRepository;
  
          _session = session;
      }
  
      [HttpPost]
      public async Task&lt;IActionResult&gt; IndexAsync(IFormCollection form)
      {
          var base64Response = form[&quot;SAMLResponse&quot;].ToString();
          var response = SAMLHelper.GetAuthnResponse(base64Response);
  
          var cachedRequest = _requestRepository.Read();
          var idpMetadata = await SamlHandler.DownloadIdPMetadata(_httpClientFactory,
              _idpRepository.Read().OrganizationUrlMetadata);
  
          var validationResult = ResponseValidator.ValidateAuthnResponse(response, cachedRequest, idpMetadata);
  
          if (validationResult.IsSuccess)
          {
              _responseRepository.Write(response);
              _session.Logged = true;
              ViewData[&quot;UserInfo&quot;] = CreateUserInfo(response);
              return View();
          }
          else
          {
              ViewData[&quot;Message&quot;] = validationResult.Error;
              return View(&quot;Error&quot;);
          }
      }
  
      [HttpPost]
      public IActionResult Logout(IFormCollection form)
      {
          var base64Response = form[&quot;SAMLResponse&quot;].ToString();
          return View();
      }
  
      
  
      [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
      public IActionResult Error()
      {
          return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
      }
  
      #region Utilities
  
      private Dictionary&lt;string, string&gt; CreateUserInfo(AuthnResponse response)
      {
          if (response == null) throw new ArgumentException(nameof(response));
  
          var attributes = response.GetAssertion().GetAttributeStatement().Items;
  
          var userDictionary = new Dictionary&lt;string, string&gt;();
  
          foreach (var attribute in attributes)
          {
              var attr = (AttributeType)attribute;
              userDictionary.Add(attr.Name, (string)attr.AttributeValue.First());
          }
  
          return userDictionary;
      }
  
      #endregion
  }
  </code></pre>
  <p>In my case, there is no problem when acs/index method is called by a POST request.</p>
  <p>When I invoke the Logout procedure (from another controller) the request is sent correctly by my application but when IdP responds to me I obtain this response on my browser:
  <a href="https://acs/logout?SAMLResponse=fVLBSsNAEL0L%2FYeS%2Bya72b%20%E2%80%A6" rel="nofollow noreferrer">https:///acs/logout?SAMLResponse=fVLBSsNAEL0L%2FYeS%2Bya72b …</a> with a 405 error.</p>
  <p>This is my <strong>Startup.cs</strong> :</p>
  <pre><code>public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddControllersWithViews();
  
          services.AddSingleton&lt;IRequestRepository, RequestRepository&gt;();
          services.AddSingleton&lt;IIdpRepository, IdpRepository&gt;();
          services.AddSingleton&lt;IResponseRepository, ResponseRepository&gt;();
  
          services.AddSingleton&lt;AppSessionViewModel&gt;();
          
          services.AddHttpClient();
  
          services.Configure&lt;Spid&gt;(Configuration.GetSection(&quot;Spid&quot;));
      }
  
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler(&quot;/Home/Error&quot;);
              app.UseHsts();
          }
  
          //app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseCookiePolicy();
          //app.UseSession();
  
          app.UseRouting();
  
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapControllerRoute(
                  name: &quot;default&quot;,
                  pattern: &quot;{controller=Home}/{action=Index}/{id?}&quot;);
          });
      }
  }
  </code></pre>
  <p>And this is my launchSettings.json (I use SPID_Test as web browser):</p>
  <pre><code>&quot;iisSettings&quot;: {
  &quot;windowsAuthentication&quot;: false,
  &quot;anonymousAuthentication&quot;: true,
  &quot;iisExpress&quot;: {
    &quot;applicationUrl&quot;: &quot;http://localhost:15378&quot;,
    &quot;sslPort&quot;: 0
  }
  </code></pre>
  <p>},</p>
  <pre><code>&quot;profiles&quot;: {
  &quot;IIS Express&quot;: {
    &quot;commandName&quot;: &quot;IISExpress&quot;,
    &quot;launchBrowser&quot;: true,
    &quot;environmentVariables&quot;: {
      &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
    }
  }
  
  &quot;SPID_Test&quot;: {
    &quot;commandName&quot;: &quot;Project&quot;,
    &quot;launchBrowser&quot;: true,
    &quot;environmentVariables&quot;: {
      &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Production&quot;
    },
    &quot;dotnetRunMessages&quot;: &quot;true&quot;,
    &quot;applicationUrl&quot;: &quot;http://localhost:5000&quot;
  }
  </code></pre>