Skip to content

Instantly share code, notes, and snippets.

@tekguy
Last active August 29, 2015 14:02
Show Gist options
  • Save tekguy/2ea019f3a7f1fae2128f to your computer and use it in GitHub Desktop.
Save tekguy/2ea019f3a7f1fae2128f to your computer and use it in GitHub Desktop.
Logging off ACS
public ActionResult LogOff()
{
// Load Identity Configuration
FederationConfiguration config = FederatedAuthentication.FederationConfiguration;
// Get wtrealm from WsFederationConfiguation Section
string wtrealm = config.WsFederationConfiguration.Realm;
string wreply;
// Construct wreply value from wtrealm (This will be the return URL to your app)
wreply = wtrealm;
// Read the ACS Ws-Federation endpoint from web.Config
// something like "https://<your-namespace>.accesscontrol.windows.net/v2/wsfederation"
string wsFederationEndpoint = ConfigurationManager.AppSettings["ida:Issuer"];
SignOutRequestMessage signoutRequestMessage = new SignOutRequestMessage(new Uri(wsFederationEndpoint));
signoutRequestMessage.Parameters.Add("wreply", wreply);
signoutRequestMessage.Parameters.Add("wtrealm", wtrealm);
FederatedAuthentication.SessionAuthenticationModule.SignOut();
string signoutUrl = signoutRequestMessage.WriteQueryString();
return this.Redirect(signoutUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment