Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Why can't I login to the web even though the User and password are correct ?

Why can't I login to the web even though the User and password are correct ?

Scheduled Pinned Locked Moved ASP.NET
databasesql-serverdesignsysadminhelp
9 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2456424
    wrote on last edited by
    #1

    I am writing a small example of Login webSite, there are two types of accounts and passwords, one is an account and password is stored in the Web.config file and the other two accounts and passwords are saved in SQL Server database, My problem is that in form 1, when logging in it opens Logon_Redirect.aspx file but cannot access, the following is my code I am debugging and running to the code where this opens the Logon_Redirect.aspx file but nothing, but when I log in with another account and password (the user password of SQL Server) log in well.

    In file Web.config
    ...

    ...

    In file Logon_Redirect.aspx
    ...

    Untitled Page

    In file Logon_Redirect.aspx.cs
    ...
    public partial class Logon_Redirect : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    // kiem tra va Redirect toi trang can thiet
    if (Page.User.IsInRole(Globals.Settings.AppRoles.KhachHang))
    Response.Redirect(Globals.ApplicationPath);
    else if (Page.User.IsInRole(Globals.Settings.AppRoles.Admin))
    Response.Redirect(Globals.ApplicationPath + "WebMaster/Contacts/Contact.aspx");
    }
    }

    In file Logon.aspx.cs
    protected void btLogon_Click(object sender, EventArgs e)
    {
    //I can't Login User/Pass in file Web.config, check User: admin and Pass: 123
    if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
    {
    if (Request.QueryString["ReturnUrl"] != null)
    {
    FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
    }
    else
    {
    FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
    Session["username"] = txtEmail.Text.Trim();
    Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");
    //I am debugging and running to the code here and opens the Logon_Redirect.aspx file but nothing
    }
    }
    else //Login SQL Server very good
    {
    // check User/pass other on SQL Server
    if (webapp4U.BOL.User.CheckUserName(txtEmail.Text) && txtPassword.Text == ConfigurationManager.AppSettings["Password"].ToString())
    {
    FormsAut

    Z Richard DeemingR 2 Replies Last reply
    0
    • U User 2456424

      I am writing a small example of Login webSite, there are two types of accounts and passwords, one is an account and password is stored in the Web.config file and the other two accounts and passwords are saved in SQL Server database, My problem is that in form 1, when logging in it opens Logon_Redirect.aspx file but cannot access, the following is my code I am debugging and running to the code where this opens the Logon_Redirect.aspx file but nothing, but when I log in with another account and password (the user password of SQL Server) log in well.

      In file Web.config
      ...

      ...

      In file Logon_Redirect.aspx
      ...

      Untitled Page

      In file Logon_Redirect.aspx.cs
      ...
      public partial class Logon_Redirect : System.Web.UI.Page
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      // kiem tra va Redirect toi trang can thiet
      if (Page.User.IsInRole(Globals.Settings.AppRoles.KhachHang))
      Response.Redirect(Globals.ApplicationPath);
      else if (Page.User.IsInRole(Globals.Settings.AppRoles.Admin))
      Response.Redirect(Globals.ApplicationPath + "WebMaster/Contacts/Contact.aspx");
      }
      }

      In file Logon.aspx.cs
      protected void btLogon_Click(object sender, EventArgs e)
      {
      //I can't Login User/Pass in file Web.config, check User: admin and Pass: 123
      if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
      {
      if (Request.QueryString["ReturnUrl"] != null)
      {
      FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
      }
      else
      {
      FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
      Session["username"] = txtEmail.Text.Trim();
      Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");
      //I am debugging and running to the code here and opens the Logon_Redirect.aspx file but nothing
      }
      }
      else //Login SQL Server very good
      {
      // check User/pass other on SQL Server
      if (webapp4U.BOL.User.CheckUserName(txtEmail.Text) && txtPassword.Text == ConfigurationManager.AppSettings["Password"].ToString())
      {
      FormsAut

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      I am not sure what you want us to do. You have to debug this, we can't do it for you. And in case you do not know, storing passwords in the web.config is not a good idea nor storing them in the db either. You should store hashes, but that's another topic for another time.

      Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

      U 1 Reply Last reply
      0
      • U User 2456424

        I am writing a small example of Login webSite, there are two types of accounts and passwords, one is an account and password is stored in the Web.config file and the other two accounts and passwords are saved in SQL Server database, My problem is that in form 1, when logging in it opens Logon_Redirect.aspx file but cannot access, the following is my code I am debugging and running to the code where this opens the Logon_Redirect.aspx file but nothing, but when I log in with another account and password (the user password of SQL Server) log in well.

        In file Web.config
        ...

        ...

        In file Logon_Redirect.aspx
        ...

        Untitled Page

        In file Logon_Redirect.aspx.cs
        ...
        public partial class Logon_Redirect : System.Web.UI.Page
        {
        protected void Page_Load(object sender, EventArgs e)
        {
        // kiem tra va Redirect toi trang can thiet
        if (Page.User.IsInRole(Globals.Settings.AppRoles.KhachHang))
        Response.Redirect(Globals.ApplicationPath);
        else if (Page.User.IsInRole(Globals.Settings.AppRoles.Admin))
        Response.Redirect(Globals.ApplicationPath + "WebMaster/Contacts/Contact.aspx");
        }
        }

        In file Logon.aspx.cs
        protected void btLogon_Click(object sender, EventArgs e)
        {
        //I can't Login User/Pass in file Web.config, check User: admin and Pass: 123
        if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
        {
        if (Request.QueryString["ReturnUrl"] != null)
        {
        FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
        }
        else
        {
        FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
        Session["username"] = txtEmail.Text.Trim();
        Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");
        //I am debugging and running to the code here and opens the Logon_Redirect.aspx file but nothing
        }
        }
        else //Login SQL Server very good
        {
        // check User/pass other on SQL Server
        if (webapp4U.BOL.User.CheckUserName(txtEmail.Text) && txtPassword.Text == ConfigurationManager.AppSettings["Password"].ToString())
        {
        FormsAut

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Member 2458467 wrote:

        if (Page.User.IsInRole(Globals.Settings.AppRoles.KhachHang))

        There's nothing in the code you've posted to show how you're loading the roles for the user. If you're not loading the roles, then the user won't be in any roles, and your Page_Load method won't redirect at all.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        U 1 Reply Last reply
        0
        • Z ZurdoDev

          I am not sure what you want us to do. You have to debug this, we can't do it for you. And in case you do not know, storing passwords in the web.config is not a good idea nor storing them in the db either. You should store hashes, but that's another topic for another time.

          Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

          U Offline
          U Offline
          User 2456424
          wrote on last edited by
          #4

          I login the user/pass of the normal sql server but I cannot login the user/pass of file web.config, you can not view the image file I can login [http://www.mediafire.com/file/wydeh0jm629lchm/website2010\_09.jpg\](http://www.mediafire.com/file/wydeh0jm629lchm/website2010\_09.jpg)

          Z 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Member 2458467 wrote:

            if (Page.User.IsInRole(Globals.Settings.AppRoles.KhachHang))

            There's nothing in the code you've posted to show how you're loading the roles for the user. If you're not loading the roles, then the user won't be in any roles, and your Page_Load method won't redirect at all.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            U Offline
            U Offline
            User 2456424
            wrote on last edited by
            #5

            If so, why can I login the sql server's user/password ?

            protected void btLogon_Click(object sender, EventArgs e)
            {
            if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text)) //web.config
            {
            ...
            }
            else //sql
            {
            ...
            }
            }

            Richard DeemingR 1 Reply Last reply
            0
            • U User 2456424

              I login the user/pass of the normal sql server but I cannot login the user/pass of file web.config, you can not view the image file I can login [http://www.mediafire.com/file/wydeh0jm629lchm/website2010\_09.jpg\](http://www.mediafire.com/file/wydeh0jm629lchm/website2010\_09.jpg)

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              What do you want us to do?

              Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

              1 Reply Last reply
              0
              • U User 2456424

                If so, why can I login the sql server's user/password ?

                protected void btLogon_Click(object sender, EventArgs e)
                {
                if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text)) //web.config
                {
                ...
                }
                else //sql
                {
                ...
                }
                }

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                You can log in, but in the code you've posted, you're not assigning any roles to the user. Any calls to User.IsInRole will therefore return false. ASP.NET 3.5 - Roles | Microsoft Docs[^]


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                U 1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  You can log in, but in the code you've posted, you're not assigning any roles to the user. Any calls to User.IsInRole will therefore return false. ASP.NET 3.5 - Roles | Microsoft Docs[^]


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  U Offline
                  U Offline
                  User 2456424
                  wrote on last edited by
                  #8

                  You can log in, but in the code you've posted, you're not assigning any roles to the user. Any calls to User.IsInRole will therefore return false. ASP.NET 3.5 - Roles | Microsoft Docs[^] I don't understand you saying "Any calls to User.IsInRole will therefore return false." Can you tell me where this is ? How do I edit the code? I debug in the button_click event code, I see

                  protected void btLogon_Click(object sender, EventArgs e)
                  {
                  if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
                  {
                  try
                  {
                  if (Request.QueryString["ReturnUrl"] != null)
                  {
                  FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
                  }
                  else
                  {
                  FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                  Session["username"] = txtEmail.Text.Trim();
                  Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");//You see the message output in the attached image, I choose yes
                  }
                  }
                  catch (Exception ex)
                  {
                  Debug.Print("Error login sql: " + ex);
                  }
                  }
                  else
                  {
                  try
                  {
                  // kiem tra xem co UserName hay ko
                  if (txtEmail.Text==ConfigurationManager.AppSettings["EmailWebmaster"].ToString() && txtPassword.Text == ConfigurationManager.AppSettings["Password"].ToString())
                  {
                  FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                  Session["username"] = txtEmail.Text.Trim();
                  Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");//You see the message output in the attached image, I choose yes
                  }
                  else
                  lblMsg.Text = ResourceManager.GetString("Logon_False");

                              }
                              catch (Exception ex)
                              {
                                  Debug.Print("Error Web.config: " + ex);
                              }
                          }
                          
                      }
                  

                  I am debugging both the user/pass sql server and user/pass cases in the Web.config file when I came to the code "Response.Redirect (Globals.ApplicationPath +" Logon_Redirect.aspx ");" In both cases, a notification is sent to view the http://www.me

                  Richard DeemingR 1 Reply Last reply
                  0
                  • U User 2456424

                    You can log in, but in the code you've posted, you're not assigning any roles to the user. Any calls to User.IsInRole will therefore return false. ASP.NET 3.5 - Roles | Microsoft Docs[^] I don't understand you saying "Any calls to User.IsInRole will therefore return false." Can you tell me where this is ? How do I edit the code? I debug in the button_click event code, I see

                    protected void btLogon_Click(object sender, EventArgs e)
                    {
                    if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
                    {
                    try
                    {
                    if (Request.QueryString["ReturnUrl"] != null)
                    {
                    FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
                    }
                    else
                    {
                    FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                    Session["username"] = txtEmail.Text.Trim();
                    Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");//You see the message output in the attached image, I choose yes
                    }
                    }
                    catch (Exception ex)
                    {
                    Debug.Print("Error login sql: " + ex);
                    }
                    }
                    else
                    {
                    try
                    {
                    // kiem tra xem co UserName hay ko
                    if (txtEmail.Text==ConfigurationManager.AppSettings["EmailWebmaster"].ToString() && txtPassword.Text == ConfigurationManager.AppSettings["Password"].ToString())
                    {
                    FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                    Session["username"] = txtEmail.Text.Trim();
                    Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");//You see the message output in the attached image, I choose yes
                    }
                    else
                    lblMsg.Text = ResourceManager.GetString("Logon_False");

                                }
                                catch (Exception ex)
                                {
                                    Debug.Print("Error Web.config: " + ex);
                                }
                            }
                            
                        }
                    

                    I am debugging both the user/pass sql server and user/pass cases in the Web.config file when I came to the code "Response.Redirect (Globals.ApplicationPath +" Logon_Redirect.aspx ");" In both cases, a notification is sent to view the http://www.me

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #9

                    There is nothing in any of the code you've posted that sets the roles for a user. Computers aren't magic. If you don't tell the system that the user is in a particular role, then it doesn't have any way to know that the user is in that role. When you later ask it if the user is in that role, the only answer it can give you is "no". Follow the link I provided in my previous message, and read about how to set up your application to support user roles. (And you can ignore the ThreadAbortException - that's a normal part of redirecting the user to another page.)


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups