Asp.net中基於角色驗證授權
阿新 • • 發佈:2019-01-09
{
7 string userRoles = UserToRole(user); //呼叫UserToRole方法來獲取role字元 8串
9 FormsAuthenticationTicket Ticket =new FormsAuthenticationTicket
10(1,user,DateTime.Now, DateTime.Now.AddMinutes(30), false,userRoles,”/”)
11; //建立身份驗證票物件12string HashTicket = FormsAuthentication.Encrypt (Ticket) ; //加密序列化驗證13票為字串
14 HttpCookie UserCookie =new HttpCookie(FormsAuthentication.FormsCook-15ieName, HashTicket) ;
16//生成Cookie17 Context.Response.Cookies.Add (UserCookie) ; //輸出Cookie18 Context.Response.Redirect (Context.Request[“ReturnUrl”]) ; // 重定向到用19戶申請的初始頁面
20 }
7 string userRoles = UserToRole(user); //呼叫UserToRole方法來獲取role字元 8串
9 FormsAuthenticationTicket Ticket =new FormsAuthenticationTicket
10(1,user,DateTime.Now, DateTime.Now.AddMinutes(30), false,userRoles,”/”)
11; //建立身份驗證票物件12string HashTicket = FormsAuthentication.Encrypt (Ticket) ;
14 HttpCookie UserCookie =new HttpCookie(FormsAuthentication.FormsCook-15ieName, HashTicket) ;
16//生成Cookie17 Context.Response.Cookies.Add (UserCookie) ; //輸出Cookie18 Context.Response.Redirect (Context.Request[“ReturnUrl”]) ; // 重定向到用19戶申請的初始頁面
20 }