Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

500
Visualizações
Redirect user to login if not logged in ASP.NET C#

I'm trying to develop web app in ASP.NET web forms using C# and i want to Redirect user to login if not logged but when i try to login i'm not able to redirect to the dashboard.aspx page i just found my self in login page please any one can help me :)

 protected void Page_Load(object sender, EventArgs e)
{
    if (Session["username"] == null)
    {
        Response.Redirect("login.aspx", true);
        return;
    }
    //else
    //{
    //    Response.Redirect("dashbord.aspx", true);
    //}
}

login.aspx

string user = Request["login1"];
string code = Request["pass"];
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from admin where username  = '"+user+"' and password = '"+ code + "'";
cmd.ExecuteNonQuery();
Session["username"] = user;
Session.Clear();
Session.Abandon();
Session.RemoveAll();
Response.Redirect("dashbord.aspx");
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should try and use a built in security provider. (even the simple FBA and role providers is better then this). If a user hits a page that is secured or requires a logon, then IIS will jump to logon page, and then automatic re-direct to where you were going in the first place. So, you really don't want to handle this on your own, since then simple efforts to set a web page is in a secured folder becomes easy.

See this recent post of mine - as to how this works, or at least should work. If you don't adopt a built in security system, then you will be for ever more trying to write code on near every web page to deal with the near "unlimited" ways that users can type in any old URL, and that's a challenge.

Authorization issues in asp page VB.NET

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda