?? global.asax
字號:
?<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Security.Principal" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{ ///存儲應用程序的狀態(tài)
Application.Lock();
Application["Data"] = "start";
Application.UnLock();
}
void Application_End(object sender, EventArgs e)
{
///存儲應用程序的狀態(tài)
Application.Lock();
Application["Data"] = "end";
Application.UnLock();
}
void Application_Error(object sender, EventArgs e)
{
///存儲應用程序的狀態(tài)
Application.Lock();
Application["Data"] = "error";
Application.UnLock();
}
void Session_Start(object sender, EventArgs e)
{ ///表示用戶登錄成功
Session["UserID"] = 1;
}
void Session_End(object sender, EventArgs e)
{ ///清楚對象
Session["UserID"] = null;
Session.Clear();
///取消Session
Session.Abandon();
}
protected void Application_BeginRequest(object sender,EventArgs e)
{ ///獲取當前用戶
if(HttpContext.Current.User != null)
{ ///當前用戶是否被驗證
if(HttpContext.Current.User.Identity.IsAuthenticated == true)
{ ///驗證方式是否為窗體驗證
if(HttpContext.Current.User.Identity is FormsIdentity)
{ ///創(chuàng)建驗證的Ticket
FormsIdentity formId = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket formTicket = formId.Ticket;
///獲取用戶數(shù)據(jù)及其角色
string userData = formTicket.UserData;
string[] roles = userData.Split(',');
///創(chuàng)建新的驗證
HttpContext.Current.User = new GenericPrincipal(formId,roles);
}
}
}
}
protected void Application_EndRequest(object sender,EventArgs e)
{
///驗證結束時觸發(fā)
}
</script>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -