遭遇用户无法注销和清空Cookie,请大家帮忙看看
/// <summary>/// 退出登录
/// </summary>
public static void SignOut()
{
SignOut("/");
}
/// <summary>
/// 退出登录
/// </summary>
/// <param name="gotourl">定向的URL</param>
public static void SignOut(string gotourl)
{
if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
{
//注销票据
FormsAuthentication.SignOut();
}
else
{
}
HttpContext.Current.Response.Redirect(gotourl);
HttpContext.Current.Response.End();
}
简直是能用的方法都用上了,为什么刷新页面 用户还处于登陆状态,不解!!
登陆代码
/// <summary>
/// 登录
/// </summary>
/// <param name="username" type="string">
/// <para>
/// 登录用户名
/// </para>
/// </param>
public static string SignIn(string username, string password)
{
bool isAuthenticated = IsAuthenticateds(username, password);
string roles = string.Empty;
if (isAuthenticated == true)
{
roles = UsersInRoless.GetUsersRolesString(username);
}
else
{
return "用户名或密码错误!";
}
DateTime expiration;
expiration = DateTime.Now.AddMinutes(60);
// 创建一个非永久性票
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1, // version
username, // user name
DateTime.Now, // creation
expiration,// Expiration
false, // Persistent
roles);
// 创建票的加密字符串表示形式,并将其作为数据存储在 HttpCookie 对象中
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
// Create a cookie and add the encrypted ticket to the
// cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
authCookie.Domain = FormsAuthentication.FormsCookieName;
////删除旧的同名Cookie
HttpContext.Current.Response.Cookies.Remove(authCookie.Domain);
//将此 cookie 添加到返回给用户浏览器的 cookie 集合中。
HttpContext.Current.Response.Cookies.Add(authCookie);
HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = authTicket.Expiration;
//将用户重定向到最初请求的页。
//HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(username, false));
return "";
}
web.config
<authentication mode="Forms">
<forms name=".xxx.com" loginUrl="Login.aspx" protection="All" timeout="60" path="/"/>
</authentication>
<authorization>
<allow users="*"/>
</authorization> --------------------编程问答-------------------- Cookie.Expires=[DateTime];
Response.Cookies("UserName").Expires = 0 --------------------编程问答-------------------- HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.AddHeader("pragma", "no-cache");
HttpContext.Current.Response.AddHeader("cache-control", "private");
HttpContext.Current.Response.CacheControl = "no-cache";
这样都试过了,还是不行
补充:.NET技术 , ASP.NET