复制代码 代码如下:
<location path="Doctors">
<system.web>
<authorization>
<allow roles="doctors"/> //这个在前
<deny users="*"/>
</authorization>
</system.web>
</location>
复制代码 代码如下:
string role="doctors";
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(30), false, role, "http://www.vevb.com/");//建立身份验证票对象
string HashTicket = FormsAuthentication.Encrypt(Ticket);//加密序列化验证票为字符串
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
//生成Cookie
Response.Cookies.Add(UserCookie);//输出Cookie
Response.Redirect("");//重定向到用户申请的初始页面
复制代码 代码如下:
string[] roles = authTicket.UserData.Split(new char[] { '|' });
FormsIdentity id = new FormsIdentity(authTicket);
System.Security.Principal.GenericPrincipal principal = new System.Security.Principal.GenericPrincipal(id, roles);
Context.User = principal;
新闻热点
疑难解答
图片精选