我现在准备用COOKIES判断会员的登陆情况,我在网站根目录中的web.config中设置
 <authentication mode="Forms" >
           <forms name=".MyC" loginUrl="/member/login.aspx" protection="All"/>
 </authentication>
 <authorization>
        <allow users="*" /> <!-- 允许所有用户 -->
</authorization>
然后在会员文件夹中的web.config中
<authorization>
    <allow users="MyUser" />
    <deny users="*" />
</authorization>
然后在登陆页面的程序如下:
HttpCookie MyCookie =new HttpCookie("Member_Id");
MyCookie.Value = psi.Id.ToString();
MyCookie.Expires = System.DateTime.Now.AddHours(1);
Response.Cookies.Add(MyCookie);
string Reurl=FormsAuthentication.GetRedirectUrl(accounts, false);
if (Reurl.EndsWith(URL_MEMBERSIGNIN) || Reurl=="/default.aspx") 
{
FormsAuthentication.SetAuthCookie("MyUser", false);
HttpContext.Current.Response.Redirect(URL_DEFAULT, true);//应该指向会员管理界面首页
}
else
{
FormsAuthentication.SetAuthCookie("MyUser", false);
HttpContext.Current.Response.Redirect(Reurl, true);
}
我运行后却不能保存COOKIES,一旦我关闭浏览齐重先打开还是需要登陆,请问我上面的做法有和不妥,在线等待……

解决方案 »

  1.   

    1.登录页面首先判断客户端是否存在Cookie,存在从Cookie中读取User数据,然后进行登录验证,否则让用户输入用户名和密码进行登录
    你得缺少这个环节
    参考代码:
    Login.cs
    Page_Load{
       if(Request.Cookies["Member_Id"]!=null)
       {
         //try get user data from Cookie at frist
        
       }   
    }
      

  2.   

    FormsAuthentication.SetAuthCookie("MyUser", true);可记住登录
      

  3.   

    谢谢楼上的,我把FALSE改成TRUE就OK了,非常感谢