1.前端頁面代碼: 前端頁面代碼主要顯示退出系統或者網站的可視化按鈕代碼,代碼如下:(請忽略項目關鍵字:CPU) <ul class="nav navbar-nav navbar-right"> <li class=""> <a href="javascript:;" class="user-pro ...
1.前端頁面代碼:
前端頁面代碼主要顯示退出系統或者網站的可視化按鈕代碼,代碼如下:(請忽略項目關鍵字:CPU)
<ul class="nav navbar-nav navbar-right"> <li class=""> <a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <img src="@Url.Content("~/assets/img/user2.png")" alt="">@CPU.UserProfile.User.UserID <span class="fa fa-angle-down"></span> </a> <ul class="dropdown-menu dropdown-usermenu pull-right" style="width:35px"> <li> @using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", style = "padding: 12px 0px;" })) { @Html.AntiForgeryToken() <a href="javascript:document.getElementById('logoutForm').submit()"><i class="fa fa-sign-out pull-right"></i> Log Out</a> } </li> </ul> </li> <li class="hidden-xs"><a><span>線上人數: @System.Web.HttpContext.Current.Application["OnLineUserCount"] 人</span></a></li> </ul>
2.後臺邏輯處理代碼:
後臺的代碼,主要是對前臺點擊按鈕的事件進行處理:退出系統和清除系統Cookie
[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult LogOff() { FormsAuthentication.SignOut();//退出登錄 System.Web.HttpContext.Current.Session.Abandon();//清理緩存 return RedirectToAction("Login", "Account"); }