0

我正在尝试在我的 ASP.NET 网站中创建会话以保存当前用户,但该词session没有显示为保留词,并且我不断收到错误消息!任何人都可以帮忙吗?

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
public partial  class login : System.Web.UI.Page
{
    public static string x;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password", con);
        cmd.Parameters.AddWithValue("@username", txtUserName.Text);
        cmd.Parameters.AddWithValue("@password", txtPWD.Text);
        //System.DateTime.Now
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            Response.Redirect("myprofile.aspx"); 
        }
        else
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script    language='javascript'>alert('خطأ في اسم المستخدم او كلمة المرور')</script>");
        }
    }
    protected void SqlDataSource1_Selecting(object sender, System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs e)
    {

    }
}
4

1 回答 1

3

Session 是 的继承属性,login因此您可以设置会话值,例如:this.Session["key"] = value;

于 2013-03-15T18:40:07.583 回答