System.Web.SessionState.HttpSessionState.this[string].get re



在检查了我从firebase收到的用户后,如果有注册用户,我将尝试将该用户的邮件发送到另一个带有会话的页面。但会话在其他页面上始终为空。

我的登录页面

protected async void student_giris_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
String ogrenci_email, ogrenci_sifre;
Object OBJogrenci_no;
ogrenci_email = studentMail.Text;
ogrenci_sifre = studentPassword.Text;
Boolean kayit_varmi = false;
FirestoreDb firestoreDb = FirestoreDb.Create("");
Query ogrencileriCek = firestoreDb.Collection("Students");
QuerySnapshot ogrencilerSnapshots = await ogrencileriCek.GetSnapshotAsync();

foreach (DocumentSnapshot documentSnapshot in ogrencilerSnapshots.Documents)
{
//System.Diagnostics.Debug.WriteLine("Document data for {0} document:", documentSnapshot.Id);
Dictionary<string, object> ogrenci = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in ogrenci)
{
//System.Diagnostics.Debug.WriteLine("{0}: {1}", pair.Key, pair.Value);
if (ogrenci.ContainsValue(ogrenci_email) && ogrenci.ContainsValue(ogrenci_sifre))
{
OBJogrenci_no = ogrenci["number"];
ogrenci_no = (string)OBJogrenci_no;
kayit_varmi = true;
}
}
}
if (kayit_varmi == true)
{
Session["cUser"] = studentMail.Text;
HttpContext.Current.Session.Timeout = 28800;
Response.Redirect("Student_Lessons.aspx");
}
else
{
yanlis_girisLabel.Text = "Email ya da şifrenizi kontrol ediniz...";
yanlis_girisLabel.ForeColor = System.Drawing.Color.Red;
}
}
}

我的其他页面

protected void Page_Load(object sender, EventArgs e)
{

if (Session["cUser"] != null)
{
Response.Redirect("StudentsLogin.aspx");
}
else
{
System.Diagnostics.Debug.WriteLine(Session["cUser"]);
Label1.Text = Session["cUser"].ToString();
}
}

我正在web表单应用程序中尝试此操作。我该如何解决这个问题?

这是因为kayit_varmi的值总是false。

删除大括号,这只是如果(kayit_vari==true(行

试试这个代码

protected async void student_giris_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
String ogrenci_email, ogrenci_sifre;
Object OBJogrenci_no;
ogrenci_email = studentMail.Text;
ogrenci_sifre = studentPassword.Text;
Boolean kayit_varmi = false;
FirestoreDb firestoreDb = FirestoreDb.Create("");
Query ogrencileriCek = firestoreDb.Collection("Students");
QuerySnapshot ogrencilerSnapshots = await ogrencileriCek.GetSnapshotAsync();

foreach (DocumentSnapshot documentSnapshot in ogrencilerSnapshots.Documents)
{
//System.Diagnostics.Debug.WriteLine("Document data for {0} document:", documentSnapshot.Id);
Dictionary<string, object> ogrenci = documentSnapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in ogrenci)
{
//System.Diagnostics.Debug.WriteLine("{0}: {1}", pair.Key, pair.Value);
if (ogrenci.ContainsValue(ogrenci_email) && ogrenci.ContainsValue(ogrenci_sifre))
{
OBJogrenci_no = ogrenci["number"];
ogrenci_no = (string)OBJogrenci_no;
kayit_varmi = true;
}
}

if (kayit_varmi == true)
{
Session["cUser"] = studentMail.Text;
HttpContext.Current.Session.Timeout = 28800;
Response.Redirect("Student_Lessons.aspx");
}
else
{
yanlis_girisLabel.Text = "Email ya da şifrenizi kontrol ediniz...";
yanlis_girisLabel.ForeColor = System.Drawing.Color.Red;
}
}
}
}

最新更新