我想做一个登陆界面(WEB应用程序),数据有以下:user,password,权限
我想第一,把这些数据加载到dataset(“密码”),然后查看TEXTBOX1,和TEXTBOX2的用户名和密码和dataset里面的密码对(不和sql数据库连接,再用SELECT来查)
怎么操作,因为第一个人上了后,第二个人不用连接数据库,直接在内存里面和dataset(“密码”)核对,这样速度快些
二,我怎么按权限做出分别,因为不同权限访问不同的网页,在vb6里面可以这样
Set td = New ADODB.Recordset
td.Open "select * from login where [用户名] ='" & Combo1.Text & " ' and 密码='" & txtPassword.Text & "'", db, adOpenKeyset, adLockBatchOptimistic
有一个IF TEXT1=td!权限 THEN
但现在怎么办我现在的代码是连接数据库核对身份,代码如下:
STR = "SELECT * FROM [WDUSER] WHERE (([用户名] = '" & TextBox1.Text & "') AND ([密码] = '" & TextBox2.Text & "'))"
             Dim objcom As New SqlCommand(STR, CONN)
            objcom.Connection.Open()
             Dim OBJDR As SqlDataReader
             OBJDR = objcom.ExecuteReader()
             If OBJDR.Read() Then
                    Server.Transfer("DEFAULT3.ASPX")
             Else
                    Label4.Text = "用户名和密码不正确!"
             End If请各位大虾帮我,急

解决方案 »

  1.   

    使用Forms验证。上msdn的网站上找一下关于MemberShip、MemberShipUser、Roles相关的内容。
      

  2.   

    创建一个登陆页login.aspx
    里面放两个TextBox 和一个按钮,在按钮的单击事件里写代码:
    private void btnLogin_Click(object sender, System.EventArgs e)
    {/
    /初始化FormsAuthentication
    FormsAuthentication.Initialize();
    //创建个connection 和command 对象
    SqlConnection conn = new
    SqlConnection("server=(local);uid=sa;pwd=mydream54win;database=web");
    SqlCommand cmd = conn.CreateCommand();
    cmd.CommandText = "select roles from users where username=@username and
    password=@password";
    //添加参数以及给参数赋值
    cmd.Parameters.Add("@username",SqlDbType.VarChar,64);
    cmd.Parameters["@username"].Value = Username.Value;
    cmd.Parameters.Add("@password",SqlDbType.VarChar,128);
    cmd.Parameters["@password"].Value = Password.Value;
    //打开数据库连接
    conn.Open();
    //执行命令
    SqlDataReader reader = cmd.ExecuteReader();
    if(reader.Read())
    {/
    /创建一个新的验证票FormsAuthenticationTicket
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
    1,//票版本号
    Username.Value,//cookie 名字
    DateTime.Now,//生成cookie 时间
    DateTime.Now.AddMinutes(30),//cookie 的有效时间
    false,//是不是永久存在的cookie
    reader.GetString(0));//从数据库读到的用户角色数据
    //把验证票加密
    string hashTicket = FormsAuthentication.Encrypt(ticket);
    //设置验证票cookie,第一个参数为cookie 的名字,第二个参数为cookie 的值也就
    是加密后的票
    HttpCookie cookie = new
    HttpCookie(FormsAuthentication.FormsCookieName,hashTicket);
    //设置cookie 的有效期是一个礼拜
    cookie.Expires = DateTime.Now.AddDays(7);
    //把cookie 加进Response 对象发生到客户端
    Response.Cookies.Add(cookie);
    //得到请求的url
    string requestUrl =
    FormsAuthentication.GetRedirectUrl(FormsAuthentication.FormsCookieName,false);
    //不要使用FormsAuthentication.RedirectFromLoginPage 方法,因为这个方法会重
    写cookie
    //重新定向到请求的url
    Response.Redirect(requestUrl);
    }e
    lse
    {
    //如果不存在此用户,则提示一些错误
    ErrorLabel.Text = "用户名或者密码错误,请重试!";
    ErrorLabel.Visible = true;
    }/
    /关闭数据库连接和reader
    reader.Close();
    conn.Close();
    }
      

  3.   

    在应用程序的Global.asax 中,找到Application_AuthenticateRequest,写下
    面代码,记的要导入using System.Security.Principal;
    using System.Web.Security;这两个名字空间,代码如下:
    protected void Application_AuthenticateRequest(Object sender,EventArgs e)
    {i
    f(HttpContext.Current.User!=null)//如果当前的http 信息中存在用户信息
    {i
    f(HttpContext.Current.User.Identity.IsAuthenticated)//如果当前用户的身份已经通
    过了验证
    {i
    f(HttpContext.Current.User.Identity is FormsIdentity)
    {
    //如果当前用户身份是FormsIdentity 类即窗体验证类,此类有个属性能够访问
    当前用户的验证票
    FormsIdentity fi = (FormsIdentity)HttpContext.Current.User.Identity;//创建个
    FormsIdentity 类,用他来访问当前用户的验证票
    //获得用户的验证票
    FormsAuthenticationTicket ticket = fi.Ticket;
    //从验证票中获得用户数据也就是角色数据
    string userData = ticket.UserData;
    //把用户数据用,分解成角色数组
    string[] roles = userData.Split(',');
    //重写当前用户信息,就是把角色信息也加入到用户信息中
    HttpContext.Current.User = new GenericPrincipal(fi,roles);
    }}}}
      

  4.   

    web.config
    <configuration>
    <system.web>
    <authentication mode="Forms">
    <forms name="MYWEBAPP.ASPXAUTH"
    loginUrl="login.aspx"
    protection="All"
    path="/"/>
    </authentication>
    <authorization>
    <allow users="*"/>
    </authorization>
    </system.web>
    <location path="admins">
    <system.web>
    <authorization>
    <!-- Order and case are important below -->
    <allow roles="Administrator"/>
    <deny users="*"/>
    </authorization>
    </system.web>
    </location>
    <location path="users">
    <system.web>
    <authorization>
    <!-- Order and case are important below -->
    <allow roles="User"/>
    <deny users="*"/>
    </authorization>
    </system.web>
    </location>
    </configuration>
      

  5.   

    你们没有懂我的意思,
    一,如何像访问SQL数据库样访问DATASET里面已经存在的表,用sql语句,如查找用"SELECT * FROM WD WHERE ....." 删除用“delete。。”等 
    二,怎么取SqlDataReader里面的值