title: How to fix "An unhandled exception occurred while processing the request."?
body: <p>As we're developing a webapp which we want to authorize  against a Shibboleth IDP we're getting the following error, after what seems like a  successfull login at the IDPP:</p>
  
  <p>An unhandled exception occurred while processing the request.</p>
  
  <p>UnexpectedInResponseToException: Received message contains unexpected InResponseTo "idd95739d3bc9e44efa1154b3e62a2e121". No cookie preserving state from the request was found so the message was not expected to have an InResponseTo attribute. This error typically occurs if the cookie set when doing SP-initiated sign on have been lost.</p>
  
  <p>Sustainsys.Saml2.Saml2P.Saml2Response.ReadAndValidateInResponseTo(XmlElement xml, Saml2Id expectedInResponseTo, IOptions options) in Saml2Response.cs, line 153</p>
  
  <p>Our startup.cs looks like this: </p>
  
  <pre><code>    services.AddAuthentication()
  .AddSaml2(options =&gt;
  {
  options.SPOptions.EntityId = new EntityId("https://adress.to.the.SP.net");
  options.SPOptions.Compatibility.UnpackEntitiesDescriptorInIdentityProviderMetadata = true;
  
  options.SPOptions.ReturnUrl = new Uri(@"https://adress.to.a.site.of.our.site.net.net/Saml/Session");
  
  options.SPOptions.ServiceCertificates.Add(new X509Certificate2(@"wwwroot/mycert.pfx"));    // "Sustainsys.Saml2.Tests.pfx"
  
  options.IdentityProviders.Add(
  new IdentityProvider(
  new EntityId("adress.to.the.IDP.net"), options.SPOptions) 
  {
  LoadMetadata = true,
  MetadataLocation = ("https://adress.to.the.MetadataLocation.xml")
  
  });
  
  IdentityProvider idp;
  var x = options.IdentityProviders.TryGetValue(new EntityId(Prov.Idp), out idp);
  
  X509Certificate2 ssoTest = new X509Certificate2(@"wwwroot/sso-test.pem");
  idp.SigningKeys.AddConfiguredKey(ssoTest);
  });^^^
  </code></pre>
  
  <p>This is what I see when I check the browser's dev-tools cokkies option: </p>
  
  <ol>
  <li><p>Gett 200 BIGipServer~idm~ipv4-shib-test: ! experimentation_subject_id: JSESSIONID: shib_idp_session: </p></li>
  <li><p>Post 500 .AspNetCore.Antiforgery.w5W7x28NAIs: ARRAffinity: Saml2.t8NpWx0u6S6zBFc97nzgN_IL: </p></li>
  <li>Gett 200 .AspNetCore.Antiforgery.w5W7x28NAIs: ARRAffinity: Saml2.5AYF3RXdiYbN3iolD0HCRu9P:</li>
  </ol>