上周我登录系统,没有问题,同样的代码,同样的数据库,都是正确登录进去,可到今天,奇怪的问题出现了,我登录系统的时候,竟然登录不进去(用户名和密码均正确无误)
请看我的登录页面,登录时记录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验证方式,可是我试了无数次之后,还是无法正常登录进系统,急请各位朋友帮忙啊。
请看我的登录页面,登录时记录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验证方式,可是我试了无数次之后,还是无法正常登录进系统,急请各位朋友帮忙啊。
解决方案 »
- Sessionstate引发的问题
- 随机取值
- 新手问题,设置好iis后,aspx文件在ie中预览报错,什么原因啊?
- aspx 下调用脚本函数
- |zyciis| 因为要控制另一个网站里面的某些页面信息 本来想用XMLHttp来服务器取的,但现在不行 改用<script src='...'> 这种方法,可行吗 谢
- 利用OWC制作Excel中的柱形图、饼形图、折线图的源代码,绝对经典
- 如何在客户端清除 服务器端 textbox 里的内容,避免页面刷新
- 一个简单而复杂的 asp.net 问题, Readonly Textbox 不能清空
- 为什么我写的这个注册资料修改的页不能修改资料啊?
- 根据二列排序的sql怎么写?
- 添加信息同时 保存展示图片到另一张表 如何获取id
- 在后台拼写excel
<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>
return HttpUtility.UrlDecode(cookie.Value);
{
WriteCookie("LoginUser", value); //Server.UrlEncode(value)试试
}