哪位高手有BasePage验证用户是否登录的基类,小弟学习下! 大家谁有验证用户登录的基类,最好完整代码贴出,让小弟学习一下!我自己写过一个,不过好像没用,没反应的。谢谢各位咯! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上这个不错,可以借鉴,自己在动动脑经吧~~[align=center]********************************************************本内容用 CSDN小秘书 回复每天回帖即可获得10分可用分!********************************************************[/align] public class BasePage : System.Web.UI.Page { public BasePage() { } protected override void OnInit(EventArgs O) { if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals("")) { Response.Redirect("~/Error.aspx"); } } } public partial class Error : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write(" <script>top.location.href='login.aspx'; </script>"); } } 或使用ihttphanlder http://www.cnblogs.com/jyk/archive/2008/06/19/1224257.html 你的页面在继承下basepage就可以了 public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, ImageClickEventArgs e) { if ((this.txtUsername.Text != "") && (this.txtPassword.Text != "")) { string userName = this.txtUsername.Text.Trim(); string userPwd = this.txtPassword.Text.Trim(); Response.Cookies["Username"].Value = this.txtUsername.Text; Response.Cookies["Password"].Value = this.txtPassword.Text; string aidSelect = "select * from emp where emp_name ='" + userName + "' and emp_pwd='" + userPwd + "'"; DataTable fileTable = new DataTable(); fileTable = DbAccess.GetDS(aidSelect).Tables[0]; if (fileTable.Rows.Count > 0) { string roleid = DbAccess.getFieldValue("select Role_id from RolePeopleRela where emp_id = (select emp_id from emp where emp_name ='" + userName + "' and emp_pwd='" + userPwd + "')"); Session ["RoleId"] = roleid; Response.Write("<script>alert('欢迎登陆!')</script>"); Response.Redirect("Index.aspx"); } else { //Response.Write("<script>alert('用户名与密码必须正确才能登陆!')</script>"); DbUITool.JsMsg(this.Page, "用户名与密码必须正确才能登陆!"); Response.Redirect("Login.aspx"); } } else { //Response.Write("<script>alert('用户名与密码不能为空!')</script>"); DbUITool.JsMsg(this.Page, "用户名与密码不能为空!"); } } } http://topic.csdn.net/u/20091214/13/6cd96ef5-3d18-4255-a440-d16ef6503d37.html#r_61900401 记得让页面继承 PageBase 而不是 System.Web.UI.Page 如何建立一个系统服务,并用系统服务来查询表 我在textbox中用onfocus后OnTextChanged不起作用了怎么办??? 请问软件加密的问题 GridView控件的取值问题 confirm提示时怎么让计时器走而不停下来 面试时的两个问题,让我郁闷了一个周末,看大家有什么看法 范型简单问题 怎样获取当前时间的字符串(200608151650) VS.net的安装。 "缺少标识符"的错误? javascript获取fileupload路径赋值给image控件 数据库存名称,服务器文件夹存路径,怎么用datalist显示图片?
[align=center]********************************************************
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************[/align]
{
public BasePage()
{
}
protected override void OnInit(EventArgs O)
{
if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
{
Response.Redirect("~/Error.aspx");
}
}
}
public partial class Error : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(" <script>top.location.href='login.aspx'; </script>");
}
}
或使用ihttphanlder
{
protected void Page_Load(object sender, EventArgs e)
{
} protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
{
if ((this.txtUsername.Text != "") && (this.txtPassword.Text != ""))
{
string userName = this.txtUsername.Text.Trim();
string userPwd = this.txtPassword.Text.Trim();
Response.Cookies["Username"].Value = this.txtUsername.Text;
Response.Cookies["Password"].Value = this.txtPassword.Text;
string aidSelect = "select * from emp where emp_name ='" + userName + "' and emp_pwd='" + userPwd + "'";
DataTable fileTable = new DataTable();
fileTable = DbAccess.GetDS(aidSelect).Tables[0];
if (fileTable.Rows.Count > 0)
{
string roleid = DbAccess.getFieldValue("select Role_id from RolePeopleRela where emp_id = (select emp_id from emp where emp_name ='" + userName + "' and emp_pwd='" + userPwd + "')");
Session ["RoleId"] = roleid;
Response.Write("<script>alert('欢迎登陆!')</script>");
Response.Redirect("Index.aspx");
}
else
{
//Response.Write("<script>alert('用户名与密码必须正确才能登陆!')</script>");
DbUITool.JsMsg(this.Page, "用户名与密码必须正确才能登陆!");
Response.Redirect("Login.aspx");
}
}
else
{
//Response.Write("<script>alert('用户名与密码不能为空!')</script>");
DbUITool.JsMsg(this.Page, "用户名与密码不能为空!");
}
}
}