62,025
社区成员
发帖
与我相关
我的任务
分享
//我这里用的是.ashx文件
public void ProcessRequest (HttpContext context) {
System.Web.Security.FormsAuthentication.SignOut();
//context.Session.RemoveAll();
context.Response.Redirect("login.aspx");
}
<authentication mode="Forms">
<forms name="xiaocookies" loginUrl="~/admin/login.aspx"/>
</authentication>
protected void SetDom(string userId)//省略了用户查询和验证
{
FormsAuthentication.SetAuthCookie(userId,true);//给userId用户发放权限
Response.Redirect("menu.htm");//转到admin/menu.htm页面
}
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddHours(-2);
Response.CacheControl = "no-cache";
Response.AddHeader("pragma", "no=cache");
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
/// <summary>
///pageSession 的摘要说明
/// </summary>
namespace Com.PubClass {
public abstract class pageSession : Page {
private bool _isadmin;
protected bool IsAdmin {
get {
return _isadmin;
}
set {
_isadmin = value;
}
}
protected override void OnLoad(EventArgs e) {
try {
if (Session["UserLoginID"] != null) {
this.IsAdmin = true;
} else {
Session.Abandon();
Response.Write("<script>alert('用户登录超时,请重新登录!');top.location.href='" + ResolveUrl("~/login.aspx") + "';</script>");
Response.End();
}
} catch (Exception serviceErr) {
Response.Write("会话已过期!<br/><b>详细信息:</b>" + serviceErr.Message.ToString());
Response.End();
}
base.OnLoad(e);
}
}
}