troubleshooting Question

Login twice issues

Avatar of Shade22
Shade22Flag for United States of America asked on
ASP.NETScripting LanguagesAJAX
15 Comments1 Solution1383 ViewsLast Modified:
When you log into my website, on the first time it boots you right back to the log in screen and displays the log in fields and also displays the logout button(only shows when your logged in.) along with displaying my username.  Once I log in again, it brings me to my dashboard. The default page in which the user logs in contains a masterpage in which I have included below.

MasterPage c#,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;

namespace MYSITE
{
    public partial class MYSITE : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string userName = log_Master.UserName;
            string password = log_Master.Password;
            e.Authenticated = Membership.ValidateUser(log_Master.UserName, log_Master.Password);
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            if (Membership.ValidateUser(log_Master.UserName, log_Master.Password))
            {
                try
                {
                    ds_UserKey.SelectParameters["UserName"].DefaultValue = log_Master.UserName;
                    SqlDataReader Reader = (SqlDataReader)ds_UserKey.Select(DataSourceSelectArguments.Empty);
                    Reader.Read();
                    Session["accnt"] = Reader["accnt"].ToString();
                    Session["unlc"] = Reader["Local"].ToString();
                    Session["userName"] = log_Master.UserName.ToString();
                }
                catch
                {
                    var lb_loginError = (Label)log_Master.FindControl("lb_loginError");
                    lb_loginError.Text = "The Email or Password you provided is invalid.";
                    lb_loginError.ForeColor = System.Drawing.Color.White;
                }
            }
            else
            {
                var lb_loginError = (Label)log_Master.FindControl("lb_loginError");
                lb_loginError.Text = "The Email or Password you provided is invalid.";
                lb_loginError.ForeColor = System.Drawing.Color.White;
            }
        }

    }
}

Dashboard c#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text;

namespace MYSITE
{
    public partial class dashboard : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                    memberDataGet(Session["acct"].ToString(), "P1", Session["unlc"].ToString());
                    //Session["unlc"] = "0";
                    ace_Search.ContextKey = rbl_Search.SelectedValue + "/" + Session["unlc"].ToString();
                    div_AdminSearch.Visible = Roles.IsUserInRole("Site-Administrator");
                    div_EliteMember.Visible = Roles.IsUserInRole("EliteMember");
                
            }
            ace_Search.ContextKey = rbl_Search.SelectedValue + "/" + Session["unlc"].ToString();
        }

        protected void ddl_refresh(object sender, EventArgs e)
        {
            gv_LogHistory.Columns[4].Visible = true;
            gv_LogHistory.Columns[6].Visible = true;
            gv_LogHistory.Columns[3].Visible = true;
            gv_LogHistory.Columns[5].Visible = true;

            ds_work_hist.SelectParameters["pacct"].DefaultValue = Session["acct"].ToString();
            ds_work_hist.SelectParameters["pRtyp"].DefaultValue = null;
            ds_work_hist.SelectParameters["pRtyp"].DefaultValue = dd_plan.SelectedValue.ToString();
            ds_work_hist.SelectParameters["unlc"].DefaultValue = Session["unlc"].ToString();
           
            gv_WorkHistory.DataBind();
            if (dd_plan.SelectedValue.ToString() == "P5")
            {
                gv_LogHistory.Columns[4].Visible = false;
                gv_LogHistory.Columns[6].Visible = false;
            }
            else
            {
                gv_LogHistory.Columns[3].Visible = false;
                gv_LogHistory.Columns[5].Visible = false;
            }
        }

        protected void ddlPageSize_SelectedIndexChanged(Object sender, EventArgs e)
        {
            gv_WorkHistory.PageSize = Convert.ToInt32(ddl_PageSize.SelectedValue.ToString());

        }



        //protected void btn_memberSearch_Click(object sender, EventArgs e)
        //{
        //    ds_work_hist.SelectParameters["pRtyp"].DefaultValue = dd_plan.Text;
        //    SqlDataReader Reader = (SqlDataReader)ds_mbr_demo.Select(DataSourceSelectArguments.Empty);
        //    Reader.Read();
        //    lb_Fname.Text = Reader["ee_Fname"].ToString();
        //    lb_Mname.Text = Reader["ee_Mname"].ToString();
        //    lb_Lname.Text = Reader["ee_Lname"].ToString();
        //    lb_ee_strt.Text = Reader["ee_strt"].ToString();
        //    lb_ee_strt2.Text = Reader["ee_strt2"].ToString();
        //    lb_ee_city.Text = Reader["ee_city"].ToString();
        //    lb_ee_stat.Text = Reader["ee_stat"].ToString();
        //    lb_ee_zipc.Text = Reader["ee_zipc"].ToString();
        //    lb_ee_brdt.Text = Reader["ee_brdt"].ToString();
        //    lb_ee_sex.Text = Reader["ee_sex"].ToString();
        //}

        protected void memberDataGet(string acct, string Rtyp, string unlc)
        {
            try
            {
                //gv_WorkHistory.DataSource = null;
                ds_mbr_demo.SelectParameters["pacct"].DefaultValue = acct;
                ds_mbr_demo.SelectParameters["unlc"].DefaultValue = unlc;
                ds_work_hist.SelectParameters["pacct"].DefaultValue = acct;
                ds_work_hist.SelectParameters["pRtyp"].DefaultValue = Rtyp;
                ds_work_hist.SelectParameters["unlc"].DefaultValue = unlc;
                gv_WorkHistory.DataBind();
                Session["s_Plan"] = Rtyp;
                if (Session["s_Plan"].ToString() == "P5")
                {
                    gv_LogHistory.Columns[4].Visible = false;
                    gv_LogHistory.Columns[6].Visible = false;
                }
                else
                {
                    gv_LogHistory.Columns[3].Visible = false;
                    gv_LogHistory.Columns[5].Visible = false;
                }

                ds_mbrPlan.SelectParameters["pacct"].DefaultValue = acct;
                SqlDataReader Reader2 = (SqlDataReader)ds_mbrPlan.Select(DataSourceSelectArguments.Empty);
                Reader2.Read();
                Session["s_mbrPlan"] = Reader2["mbrPlan"].ToString();



                SqlDataReader Reader = (SqlDataReader)ds_mbr_demo.Select(DataSourceSelectArguments.Empty);
                Reader.Read();
                if (Reader.HasRows)
                {
                }
                else
                {
                    Session["s_mbrPlan"] = "";
                }
                tp_PensionPlan.Visible = Session["s_mbrPlan"].ToString().Contains("p") ? true : false;
                tp_BaseFund.Visible = Session["s_mbrPlan"].ToString().Contains("b") ? true : false;
                tp_International.Visible = Session["s_mbrPlan"].ToString().Contains("i") ? true : false;

                tp_Supplement.Visible = Session["s_mbrPlan"].ToString().Contains("s") ? true : false;
                dd_plan.Items.FindByValue("zz").Enabled = Session["s_mbrPlan"].ToString().Contains("p") ? true : false;
                dd_plan.Items.FindByValue("zd").Enabled = Session["s_mbrPlan"].ToString().Contains("d") ? true : false;
                dd_plan.Items.FindByValue("za").Enabled = Session["s_mbrPlan"].ToString().Contains("s") ? true : false;
                dd_plan.Items.FindByValue("dd").Enabled = Session["s_mbrPlan"].ToString().Contains("n") ? true : false;
                dd_plan.SelectedIndex = dd_plan.Items.IndexOf(dd_plan.Items.FindByValue("P1"));

                if (Reader.HasRows)
                {
                    lb_Fname.Text = Reader["ee_Fname"].ToString();
                    lb_Mname.Text = Reader["ee_Mname"].ToString();
                    lb_Lname.Text = Reader["ee_Lname"].ToString();
                    lb_ee_strt.Text = Reader["ee_strt"].ToString();
                    lb_ee_strt2.Text = Reader["ee_strt2"].ToString();
                    lb_ee_city.Text = Reader["ee_city"].ToString();
                    lb_ee_stat.Text = Reader["ee_stat"].ToString();
                    lb_ee_zipc.Text = Reader["ee_zipc"].ToString();
                    lb_ee_brdt.Text = Reader.IsDBNull(0) ? null : String.Format("{0:MM/dd/yyyy}", Reader["ee_brdt"]);
                    lb_ee_sex.Text = Reader["ee_sex"].ToString();
                }
                gv_WorkHistory.PageSize = Convert.ToInt32(ddl_PageSize.SelectedValue.ToString());
            }
            catch (Exception ex)
            {
                lb_acctSeachError.Text = "The Account Number entered was not found." + ex;
            }
            finally
            {

            }


        }
        protected void btn_adminMemberLookup_Click(object sender, EventArgs e)
        {
            //var tb_adminMemberLookup = (TextBox)lv_AdminSearch.FindControl("tb_adminMemberLookup");
            bool validSearch = false;
            switch (rbl_Search.SelectedValue.ToUpper())
            {
                case "S":
                    if (tb_adminMemberLookup.Text.Length >= 9)
                    {
                        Session["SSN"] = tb_adminMemberLookup.Text.Substring(0, 9);
                        validSearch = true;
                    }
                    break;
                default:
                    string[] results = tb_adminMemberLookup.Text.Split('-');
                    if (results.Length == 2)
                    {
                        Session["acct"] = results[1].Trim();
                        validSearch = true;
                    }
                    break;
            }
            if (validSearch)
            {
            }

            //Session["acct"] = tb_adminMemberLookup.Text;
            memberDataGet(Session["acct"].ToString(), "ZZ", Session["unlc"].ToString());
        }
    }
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 15 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros