Guest User

Untitled

a guest
Apr 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. routes.MapRoute(
  2. "Index2Redirect",
  3. "HomeController/Index2",
  4. new { controller = "HomeController", action = "Index", id = "" }
  5. );
  6.  
  7. public class AbandonSessionAttribute: ActionFilterAttribute
  8. {
  9. public void OnActionExecuting(ActionFilterContext context)
  10. {
  11. if (Session.User.IsAuthenticated || Session.Count > 0) // <<-- this is the important line
  12. {
  13. Session.Clear();
  14. FormsAuthentication.SignOut(); // and so on
  15. context.Result = new RedirectResult("/Index2");
  16. }
  17. }
  18. }
  19.  
  20. // now, if this is called with non-empty session, it will be cleared and user will be redirected again here
  21. [AbandonSession]
  22. public ActionResult Index2()
  23. {
  24. }
  25.  
  26. Index()
  27. {
  28. expire all session and forms-Authententication cookies
  29. }
  30.  
  31. Index2()
  32. {
  33. if(Session.IsNewSession)
  34. {
  35. redirect to Index action
  36. }
  37. else
  38. {
  39. Show view
  40. }
  41. }
Add Comment
Please, Sign In to add comment