ASP.NET MVC 4 Controller 檢查 Authentication 方法

 
ASP.NET MVC 4 Controller 檢查 Authentication 方法
 

 
   public class HomeController : Controller
   {
      public ActionResult Index()
      {
         if(User.Identity.IsAuthenticated) {
            ViewBag.Login = "User : " + User.Identity.Name;
         } else {
            ViewBag.Login = "Authentication Request.";
         }
 
         return View();
      }
 
      … …
   }