日期:2014-05-17  浏览次数:20418 次

求一段登录验证程序
想做一个登陆验证,请问该怎么写呢,我用ajax提交了用户名和密码到后台,怎么去判断?

还有就是验证通过以后跳转到一个网页,如果我直接输入这个网页的地址也可以访问,

怎么让没有登录不让访问这个网页?

------解决方案--------------------
1\后台判断和正常判断是一样的 
if(Request["userName"]==....)
{
 Session["login"]=true;
 Response.Write("True");
 return
}
else{
 Response.Wirte("False")
 return 
}

2\前台接收为"true"就跳转
location.href='xxx.aspx' 或者 window.open('xxx.aspx','_top或其它');

3\每个要权限的页面都要进行Session判断
if(Session["login"]==null)
{
  ...没有登陆处理
}
------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class entry : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["userName"] = null;
        }
    }
    protected void btnEntry_Click(object sender, EventArgs e)
    {
        string userName = txtName.Text;
        string Pwd = txtPwd.Text;
        string sql = "select * from tb_user where userName='" + userName + "' and userPwd='" + Pwd + "'";
        if (dataOperate.seleSQL(sql) > 0)
      
        {
            Session["userName"] = txtName.Text;
            Response.Redirect("index.aspx");
        }
        else
        {
            RegisterStartupScript("", "<script>alert('登录失败!')</script>");
        }
    }
}


    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] != null)        //判断用户是否登录    
        {
            bindBookInfo();                     //调用自定义方法用来绑定图书借阅排行
        }
        else
           &nbs