title: WsFederation Authentication login loop
body: <p>I am experiencing a problem with a login loop when using <code>WsFederation Authentication</code> in my MVC web application. I used visual studio to create the scaffolding of the web application and to setup the <code>WsFederation</code> in the <code>Startup.cs</code>. Which generates the following block of code:</p>
  
  <pre><code>public class Startup
  {
      private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
      private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
  
      public void Configuration(IAppBuilder app)
      {
          app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
  
          app.UseCookieAuthentication(new CookieAuthenticationOptions());
  
          app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
          {
              Wtrealm = realm,
              MetadataAddress = adfsMetadata
          });
      }
  }
  </code></pre>
  
  <p>The web application is hosted in Azure and the ADFS is on premises.</p>
  
  <p>On some clients, when a login attempt is made the login page goes into a loop requesting a new tokens causing the following exception on the ADFS Server:</p>
  
  <blockquote>
    <p>Exception details: 
    Microsoft.IdentityServer.Web.InvalidRequestException: MSIS7042: The same client browser session has made '6' requests in the last '7' seconds. Contact your administrator for details.</p>
  </blockquote>
  
  <p>I have read many articles on StackOverflow and looked at the various examples provided by the guys who wrote IdentityServer and I have tried the various configuration options and I cannot isolate the problem to a specific area.</p>
  
  <p>From what I read it is a general problem with the OWIN middle ware loosing context of the object and as a result the token gets "lost".</p>
  
  <p>I have attempted to implement some of the <a href="https://stackoverflow.com/questions/28559237/intermittent-redirection-loops-during-adfs-authentication">sample code</a> that other have provided on StackOverflow but, I cannot seem to find a solution the resolves my problem or maybe a have not implemented the code correctly.</p>
  
  <p>Any Ideas?</p>