Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate session in C#
    primarykey
    data
    text
    <p>Hi I'm creating a login form from scratch in c# using 3 tiers. I've managed to build a working form that checks if the user data is correct. If he filled in the wrong data he'll get a message. But now I need to create a session to store the id. </p> <p>I've searched the web and they say you have to add <code>Session["sessionName"]= data</code>, but if I type <code>Session["userId"]=s.studentNummer</code> he doesn't recognize anything. Is it better to put the sessions in the DAL or in the DLL? I wanted to write it in the DAL (function checkLogin). Can somebody please help me?</p> <p>Here's my code:</p> <p>DALstudent.cs</p> <pre><code>public class DALstudent { dc_databankDataContext dc = new dc_databankDataContext(); public void insertStudent(Student s) { dc.Students.InsertOnSubmit(s); dc.SubmitChanges(); } public bool checkLogin(string ID, string passw) { bool canlogin = false; var result = (from s in dc.Students where s.studentNummer == ID &amp;&amp; s.studentPasswoord == passw select s).Count(); if (result == 1) { canlogin = true; } else { canlogin = false; } return canlogin; } } </code></pre> <p>BLLstudent.cs</p> <pre><code>public class BLLstudent { DALstudent DALstudent = new DALstudent(); public void insertStudent(Student s) { DALstudent.insertStudent(s); } public string getMD5Hash(string passwd) { MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); byte[] bs = Encoding.UTF8.GetBytes(passwd); bs = x.ComputeHash(bs); StringBuilder str = new StringBuilder(); foreach (byte b in bs) { str.Append(b.ToString("x2").ToLower()); } string password = str.ToString(); return password; } public bool checkLogin(string ID, string passw) { bool canlogin = DALstudent.checkLogin(ID, passw); if (canlogin == true) { return true; } else { throw new Exception("Uw gegevens kloppen niet"); } } } </code></pre> <p>login.aspx.cs</p> <pre><code>public partial class web_login : System.Web.UI.Page { protected void btnLogin_Click(object sender, EventArgs e) { try { BLLstudent BLLstudent = new BLLstudent(); var loginNr = txtLoginNr.Text; var pass = BLLstudent.getMD5Hash(txtWachtwoord.Text); var passw = pass; BLLstudent.checkLogin(loginNr, passw); Response.Redirect("student/s_procedure_goedkeuring.aspx"); } catch (Exception Ex) { lblFeedback.Text = Ex.Message; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload