上周我登录系统,没有问题,同样的代码,同样的数据库,都是正确登录进去,可到今天,奇怪的问题出现了,我登录系统的时候,竟然登录不进去(用户名和密码均正确无误)
请看我的登录页面,登录时记录cookie的代码:            //记录cookie
            CurrentLoginInfo.RememberPassword = chkRememberPwd.Checked;
            CurrentLoginInfo.LoginUser = username;
            CurrentLoginInfo.EmpID = emp.EmpID;
            CurrentLoginInfo.CNEmpName = emp.CNEmpName;//是中文名,如果把这句赋值成英文,则没问题,可以登录进去。
            FormsAuthentication.SetAuthCookie(username, false);
            FormsAuthentication.RedirectFromLoginPage(username, false);CurrentLoginInfo,是记录当前登录的用户信息,代码如下:#region 登录的用户信息
        /// <summary>
        /// 当前登录的用户名
        /// </summary>
        public static string LoginUser
        {
            get
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies["LoginUser"];
                if (cookie != null)
                    return cookie.Value;
                else
                    return string.Empty;
            }
            set
            {
                WriteCookie("LoginUser", value);
            }
        }
        /// <summary>
        /// 员工编号
        /// </summary>
        public static string EmpID
        {
            get
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies["EmpID"];
                if (cookie != null)
                    return cookie.Value;
                else
                    return string.Empty;
            }
            set
            {
                WriteCookie("EmpID", value);
            }
        }
        /// <summary>
        /// 员工姓名
        /// </summary>
        public static string CNEmpName
        {
            get
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies["CNEmpName"];
                if (cookie != null)
                    return HttpUtility.UrlDecode(cookie.Value);
                else
                    return string.Empty;
            }
            set
            {
                WriteCookie("CNEmpName", value);
            }
        }
        /// <summary>
        /// 员工模型
        /// </summary>
        public static bfEMP bfEmp
        {
            get
            {
                return new bfEMPBLL().GetModelByID(EmpID);
            }
        }
        #endregion
        /// <summary>
        /// 是否记录密码(默认一周内自动登录)
        /// </summary>
        public static bool RememberPassword{ get; set; }
        
        /// <summary>
        /// 写cookie (默认为1天)
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="value">value</param>
        private static void WriteCookie(string key, string value)
        {
            HttpCookie cookie = new HttpCookie(key, value);
            int days = 1;
            if (RememberPassword) days = 7;
            cookie.Expires = DateTime.Now.AddDays(days);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }我是用的.net的form验证方式,可是我试了无数次之后,还是无法正常登录进系统,急请各位朋友帮忙啊。

解决方案 »

  1.   

    你的web.config里面是怎么写的
    <configuration>
        <system.web>
          <compilation debug="true" targetFramework="4.0"/>
          <authentication mode="Forms">
            <forms loginUrl="Welcome.aspx" name=".ASPXAUTH"></forms>
          </authentication>
          <authorization>
            <deny users="?"></deny>
          </authorization>
        </system.web>
      
      <!-- 允许所有用户访问image文件夹-->
        <location path="image">
          <system.web>
            <authorization>
              <allow users="*"/>
            </authorization>
          </system.web>
        </location>
      <!-- 允许所有用户访问注册界面-->
      <location path="Register1.aspx">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location></configuration>
      

  2.   

    你internet的 是不是设置了完全阻止cookie啊
      

  3.   

    你写的时候HttpUtility.UrlEncode了么?FORM
      

  4.   

    写了啊,你看:
    return HttpUtility.UrlDecode(cookie.Value);
      

  5.   

    读取cookie的时候你是UrlDecode了,但你写入的时候没UrlEncode啊set
    {
        WriteCookie("LoginUser", value); //Server.UrlEncode(value)试试
     }
      

  6.   

    断点早跟过了,跟踪到login.aspx.cs 的最后一行时,没有问题,但在default.aspx.cs页面就是无论如何断点也进不去,而浏览器却还是停留在登录页面。