This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AuthenticationController : Controller | |
{ | |
ILogger _Logger = NullLogger.Instance; | |
public AuthenticationController(ILoggerFactory loggerfactory) { | |
loggerfactory.Create(Loggers.Security); | |
} | |
[AllowAnonymous] | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
//To trigger redirect to login | |
[Authorize] | |
public ActionResult SignIn() | |
{ | |
return RedirectToAction("Index", "Home"); | |
} | |
public void SignOut() | |
{ | |
WsFederationConfiguration fc = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration; | |
string request = System.Web.HttpContext.Current.Request.Url.ToString(); | |
string wreply = request.Substring(0, request.Length - 7); | |
SignOutRequestMessage soMessage = new SignOutRequestMessage(new Uri(fc.Issuer), wreply); | |
soMessage.SetParameter("wtrealm", fc.Realm); | |
SessionAuthenticationModule sam = FederatedAuthentication.SessionAuthenticationModule; | |
if (sam != null) { | |
_Logger.Debug("Calling SessionAuthenticationModule signout"); | |
sam.SignOut(); | |
sam.DeleteSessionTokenCookie(); | |
} | |
WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule; | |
if (fam != null) { | |
_Logger.Debug("Calling WSFederationAuthenticationModule.Signout()"); | |
fam.SignOut(); | |
} | |
_Logger.InfoFormat("Signed out. Redirecting..."); | |
Response.Redirect(soMessage.WriteQueryString()); | |
} | |
} |
Loading ....