私が使用しているコードは以下の通りです。これはSessionを使う正しい方法ですか?また、私がSessionを行った場合、明確にするために私はcompanyIDとuserIDをどのように呼ぶのでしょうか。 Session.ContentsかSession.Keysか?これはセッションを使用した初めてのことですが、私はhttpcontact.current.userを使用してこれにアクセスしていますが、データの各部分にアクセスする方法がわかりません。aspセッションの適切な使用と可能なインターフェイスの使用
ありがとうございます!
MySqlConnection cn = new MySqlConnection("Server=localhost;Database=users; User=root;Password=00;");
cn.Open();
string storedProcedureName = "VLID";
MySqlCommand cmd = new MySqlCommand(storedProcedureName, cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@userName", this.Login1.UserName);
cmd.Parameters.Add("@passwordID", this.Login1.Password);
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
string userID = dr["userID"].ToString();
string companyID = dr["CompanyID"].ToString();
string sessionID = Session.SessionID.ToString();
Session.Add(companyID, "companyID");
Session.Add(userID, "userID");
e.Authenticated = true;
Response.Redirect("index.html");
// Event Authenticate is true
}
は、なぜあなたは、文字列セッションIDの変数を宣言したのですか?あなたはどこでもそれを使用していません。私は、会社のID、ユーザーID、およびその他の情報を保持し、セッションに追加するユーザープロファイル構造を作成していました。それは情報を管理する別の方法です。 –