diff --git a/App_Code/Saml.cs b/App_Code/Saml.cs index d2935c5..8f89b3c 100755 --- a/App_Code/Saml.cs +++ b/App_Code/Saml.cs @@ -21,7 +21,7 @@ namespace OneLogin { namespace Saml { - public class Certificate + public class Certificate : IDisposable { public X509Certificate2 cert; @@ -46,9 +46,32 @@ private byte[] StringToByteArray(string st) } return bytes; } + #region Dispose added for .Net 4.6 + bool disposed = false; + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + cert.Dispose(); + } + + disposed = true; + } + #endregion + } - public class Response + public class Response: IDisposable { private XmlDocument xmlDoc; private AccountSettings accountSettings; @@ -135,6 +158,10 @@ public string GetNameID() XmlNode node = xmlDoc.SelectSingleNode("/samlp:Response/saml:Assertion/saml:Subject/saml:NameID",manager); return node.InnerText; } + public void Dispose() + { + certificate.Dispose(); + } } public class AuthRequest diff --git a/Consume.aspx.cs b/Consume.aspx.cs index ee995db..e3fffbc 100755 --- a/Consume.aspx.cs +++ b/Consume.aspx.cs @@ -22,17 +22,19 @@ protected void Page_Load(object sender, EventArgs e) // replace with an instance of the users account. AccountSettings accountSettings = new AccountSettings(); - OneLogin.Saml.Response samlResponse = new Response(accountSettings); - samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]); - - if (samlResponse.IsValid()) - { - Response.Write("OK!"); - Response.Write(samlResponse.GetNameID()); - } - else + using (OneLogin.Saml.Response samlResponse = new Response(accountSettings)) { - Response.Write("Failed"); + samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]); + + if (samlResponse.IsValid()) + { + Response.Write("OK!"); + Response.Write(samlResponse.GetNameID()); + } + else + { + Response.Write("Failed"); + } } } }