diff --git a/AzureAdMvcExample/Controllers/LogoutController.cs b/AzureAdMvcExample/Controllers/LogoutController.cs
new file mode 100644
index 0000000..4e50efa
--- /dev/null
+++ b/AzureAdMvcExample/Controllers/LogoutController.cs
@@ -0,0 +1,30 @@
+using System;
+using System.IdentityModel.Services;
+using System.Web.Mvc;
+
+namespace AzureAdMvcExample.Controllers
+{
+ public class LogoutController : Controller
+ {
+ public ActionResult Index()
+ {
+ var config = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration;
+
+ var callbackUrl = Url.Action("Callback", "Logout", null, Request.Url.Scheme);
+ var signoutMessage = new SignOutRequestMessage(new Uri(config.Issuer), callbackUrl);
+ signoutMessage.SetParameter("wtrealm", config.Realm);
+ FederatedAuthentication.SessionAuthenticationModule.SignOut();
+
+ return new RedirectResult(signoutMessage.WriteQueryString());
+ }
+
+ [AllowAnonymous]
+ public ActionResult Callback()
+ {
+ if (Request.IsAuthenticated)
+ return RedirectToAction("Index", "Home");
+
+ return View();
+ }
+ }
+}
\ No newline at end of file
diff --git a/AzureAdMvcExample/Views/Logout/Callback.cshtml b/AzureAdMvcExample/Views/Logout/Callback.cshtml
new file mode 100644
index 0000000..85da9a2
--- /dev/null
+++ b/AzureAdMvcExample/Views/Logout/Callback.cshtml
@@ -0,0 +1,7 @@
+@{
+ ViewBag.Title = "Logged out";
+}
+
+Logged out
+
+You have successfully logged out of this site. @Html.ActionLink("Log back in", "Index", "Home").
diff --git a/AzureAdMvcExample/Views/Shared/_Layout.cshtml b/AzureAdMvcExample/Views/Shared/_Layout.cshtml
index 9e7f719..e1251db 100644
--- a/AzureAdMvcExample/Views/Shared/_Layout.cshtml
+++ b/AzureAdMvcExample/Views/Shared/_Layout.cshtml
@@ -21,6 +21,10 @@
- @Html.ActionLink("Home", "Index", "Home")
+ @if (User.Identity.IsAuthenticated)
+ {
+ - @Html.ActionLink("Logout", "Index", "Logout")
+ }