62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ylsn.Model;
namespace ylsn.Common
{
/// <summary>
///前台用户页面的基类,同一身份验证
/// </summary>
public class CommonPage : Page
{
public CommonPage()
{
//在所有页面中利用页面加载事件统一身份验证
Load += new EventHandler(CommonPage_Load);
}
void CommonPage_Load(object sender, EventArgs e)
{
//如果不存在会员会话信息则跳转到用户登录页面
if (Session["userId"] == null)
{
JScript.AlertAndRedirect("您还没登录,请先登录!", "login.aspx", this);
}
}
}
}
namespace ylsn.Web
{
public partial class userCenter : ylsn.Common.CommonPage
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
//取得两个对象实例
int userId = (int)Session["userId"];
...
下面代码省略
...
}
}
}
}
if(Session["userId"]!=null)
{
userId=(int)Session["userId"];
}
else
{
Response.Redirect("login.aspx");
}
//取得两个对象实例
//int userId = (int)Session["userId"];
//改为:
int userId=0;
if(Session["userId"]!=null)
{
userId=(int)Session["userId"];
}