0

I ran into a big problem here that I just dont know what to do in anymore. Before I added the login system the Response.Redirect worked like a charm. But I know that the login works fine I ran debug on it and all the files works fine and goes on as it should.

EDIT 1: I noticed if I commentate Master.UserLogin(arr); out from the default btnLogin_click and type Server.Transfer(@"~\Admin\Side.aspx"); it works again but I dont see why making a session will stop the response?

EDIT 2: Okay so it seems like it has to do something with the site.master.cs where I create session varriabler and after tries to redirect to another page. how do I fix this?

Default.aspx.cs

protected void btnLogin_Click(object sender, EventArgs e)
{
    db.ConnOpenHelpdesk();
    if (db.HelpdeskDBLogin(txtBrugernavn.Text, txtPassword.Text).Count() == 8)
    {
        if (db.HelpdeskDBLogin(txtBrugernavn.Text, txtPassword.Text)[7] == "2" || db.HelpdeskDBLogin(txtBrugernavn.Text, txtPassword.Text)[7] == "1")
        {
            Master.UserLogin(db.HelpdeskDBLogin(txtBrugernavn.Text, txtPassword.Text));
        }
    }
    else
    {
        db.ConnCloseHelpdesk();
        lblError.ForeColor = Color.Red;
        lblError.Visible = true;
        lblError.Text = "Dit Brugernavn og Password passer ikke sammen prøv igen.";
    }
    //Master.UserLogin(txtBrugernavn.Text, txtPassword.Text);
}

DBControl.cs

public string[] HelpdeskDBLogin(string brugernavn, string password)
{
    string sql = "SELECT * FROM Admin WHERE Brugernavn = '" + brugernavn + "' AND Password = '" + password + "'";
    SqlCommand command = new SqlCommand(sql, m_helpdeskconnection);
    SqlDataReader reader = command.ExecuteReader();
    if (reader.HasRows)
    {
        while (reader.Read())
        {
            arr = new string[8] { "" + reader["ID"], "" + reader["Brugernavn"], "" + reader["Password"], "" + reader["Email"], "" + reader["TelefonNr"], "" + reader["Navn"], "" + reader["Nytpass"], "2" };
        }
        reader.Close();
        return arr;
    }
    else
    {
        reader.Close();
        string sql2 = "SELECT * FROM Kunder WHERE Brugernavn = '" + brugernavn + "' AND Password = '" + password + "'";
        SqlCommand command2 = new SqlCommand(sql2, m_helpdeskconnection);
        SqlDataReader reader2 = command2.ExecuteReader();
        if (reader2.HasRows)
        {
            while (reader.Read())
            {
                arr = new string[8] { "" + reader["KundeNr"], "" + reader["Brugernavn"], "" + reader["Password"], "" + reader["Email"], "" + reader["TelefonNr"], "" + reader["Navn"], "" + reader["Nytpass"], "1" };
            }
            reader2.Close();
            return arr;
        }

        else
        {
            reader2.Close();
            string[] arr = new string[1];
            return arr;
        }
    }
}

Site.Master.cs

public void UserLogin(string[] arr)
{
    if (arr[7] == "1")
    {
        Session["Kundenr"] = arr[0];
        Session["Brugernavn"] = arr[1];
        Session["Email"] = arr[3];
        Session["TelefonNr"] = arr[4];
        Session["Kundenavn"] = arr[5];
        Session["Nytpass"] = arr[6];
        Session["Rang"] = arr[7];
        Response.Redirect(@"~\Bruger\Side.aspx");
    }
    else if (arr[7] == "2")
    {
        Session["Kundenr"] = arr[0];
        Session["Brugernavn"] = arr[1];
        Session["Email"] = arr[3];
        Session["TelefonNr"] = arr[4];
        Session["Kundenavn"] = arr[5];
        Session["Nytpass"] = arr[6];
        Session["Rang"] = arr[7];
        Response.Redirect(@"~\Admin\Side.aspx");
    }
}
Masoud Mohammadi
  • 1,721
  • 1
  • 23
  • 41
BlackStarHH
  • 75
  • 2
  • 11
  • Always when i see something like `db.ConnOpenHelpdesk` i cringe. All the more in ASP.NET. I hope `m_helpdeskconnection` is not static. http://stackoverflow.com/questions/9705637/executereader-requires-an-open-and-available-connection-the-connections-curren/9707060#9707060 – Tim Schmelter Aug 18 '14 at 08:15
  • the sqlconnection is not a static no but the connection works fine it gets the data needed and so on but it wont change site anymore for some reason – BlackStarHH Aug 18 '14 at 08:29
  • the db is also a new class I made – BlackStarHH Aug 18 '14 at 09:46

2 Answers2

0

You are not setting authentication cookies. As a result, your user is redirected back to login screen since he does not have rights to view internal pages of your website.

Norfolc
  • 458
  • 3
  • 10
  • My authentication runs trough sessions where I got a session called Rang that reads from the db. and right now all authentication is turned off to see it that did the job and nope. – BlackStarHH Aug 18 '14 at 08:32
  • @user3415760 have you checked what response you are receiving in browser (e.g. in network monitor in chrome)? – Norfolc Aug 18 '14 at 08:45
  • I did now and I see its getting the response from the new page but for some reason its not picking it up and then it gets a new response from the default site and takes that one if I commentate the session part out and run without session it works but I dont see why – BlackStarHH Aug 18 '14 at 08:59
0

Okay I found out what the problem was. I had a Session created in string but I tested it inside my masterpage if it was an int and then it logged me out. so problem is solved ty for all of your time

BlackStarHH
  • 75
  • 2
  • 11