<!--
通过 <authentication> 节可以配置 ASP.NET 用来
识别进入用户的
安全身份验证模式。
-->
<authentication mode ="Forms" >
<forms loginUrl="Login.aspx" name ="login"></forms>
</authentication>
<authorization>
<deny users ="?"/>
<allow roles ="admin"/>
</authorization>
//创建一个验证票据
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, txtName.ToString().Trim(), DateTime.Now,
DateTime.Now.AddMinutes(30), true, "User");
//并且加密票据
string cookieStr = FormsAuthentication.Encrypt(ticket);
//创建cookie
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieStr);
////保存密码 在这里可以不保存密码
//if (true)
//cookie.Expires = ticket.Expiration;//设置cookie有效期
//cookie存放路径
cookie.Path = FormsAuthentication.FormsCookiePath;
//添加到Cookies集合中
Response.Cookies.Add(cookie);
<!--意思是让这个目录给所有的用户访问-->
<location path ="images">
<system.web >
<authorization>
<allow users ="?"/>
</authorization>
</system.web>
</location>
<!--意思是让这个目录给所有的用户访问-->
<location path ="SystemSetting/CheckCode.aspx">
<system.web >
<authorization>
<allow users ="?"/>
</authorization>
</system.web>
</location>
<system.web>
欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |