コード例 #1
0
        //// GET ORGID AND USERID FROM ASPNET MEMBERSHIP STATUS ////
        protected void GetOrgUserFromMembership()
        {
            // Instantiate SQL String
            string SelectOrgIDSQL;

            // Select SQL
            SelectOrgIDSQL =
                "SELECT tbl_UsersMaster.UserID, tbl_UsersMaster.OrgID FROM tbl_UsersMaster, aspnet_Users WHERE tbl_UsersMaster.aspnetId ='" +
                FetchUser.UserID() + "'";

            // Use SQL Statement to Select Records from DB
            var sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
            var cmd     = new SqlCommand(SelectOrgIDSQL, sqlConn);

            cmd.Connection.Open();
            SqlDataReader OrgIdRdr;

            OrgIdRdr = cmd.ExecuteReader();

            while (OrgIdRdr.Read())
            {
                string sOrgID = OrgIdRdr["OrgID"].ToString();
                lbl_OrgID.Text = sOrgID;
                // Set Session
                Session["OrgID"] = sOrgID;

                string sUserID = OrgIdRdr["UserID"].ToString();
                lbl_UserID.Text = sUserID;
                // Set Session
                Session["UserID"] = sUserID;
            }

            cmd.Connection.Close();
            cmd.Connection.Dispose();
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // First Load Events
            if (!IsPostBack)
            {
                // IF LOGGED IN GRAB DETAILS AND POPULATE WITH ASP.NET ID
                if (User.Identity.IsAuthenticated)
                {
                    lbl_UserID.Text = FetchUser.UserID();
                    GetOrgUserFromMembership();
                    GetOrgDetails();
                    GetLeaders();
                    BindConvList();
                }

                // ELSE IF QUERYSTRING EXISTS USE IT TO GRAB DETAILS AND POPULATE
                else if (!String.IsNullOrEmpty(Request.QueryString["Token"]))
                {
                    string sToken = Request.QueryString["Token"];
                    Session["Token"] = sToken;
                    lbl_Token.Text   = Session["Token"].ToString();

                    GetOrgUserFromToken();
                    GetOrgDetails();
                    GetLeaders();
                    BindConvList();
                }

                // ELSE IF SESSION VARIABLE IS POPULATED
                else if (Session["UserID"] != null)
                {
                    GetOrgUserFromSession();
                    GetOrgDetails();
                    GetLeaders();
                    BindConvList();
                }

                else
                {
                    // ELSE IF NOT LOGGED IN NOR USING TOKEN NOR SESSION SEND TO DEFAULT PAGE
                    Response.Redirect("/Default.aspx");
                }

                // Show Divs
                divPublicConv.Visible              = true;
                divPrivateConv.Visible             = false;
                lbn_publicConversations.ForeColor  = Color.OrangeRed;
                lbn_privateConversations.ForeColor = Color.CadetBlue;
            }

            // If Session Variable is Lost
            if (Session["UserID"] == null)
            {
                // IF LOGGED IN GRAB DETAILS AND POPULATE WITH ASP.NET ID
                if (User.Identity.IsAuthenticated)
                {
                    lbl_UserID.Text = FetchUser.UserID();
                    GetOrgUserFromMembership();
                    GetOrgDetails();
                    GetLeaders();
                    BindConvList();
                }

                // ELSE IF QUERYSTRING EXISTS USE IT TO GRAB DETAILS AND POPULATE
                else if (!String.IsNullOrEmpty(Request.QueryString["Token"]))
                {
                    string sToken = Request.QueryString["Token"];
                    Session["Token"] = sToken;
                    lbl_Token.Text   = Session["Token"].ToString();

                    GetOrgUserFromToken();
                    GetOrgDetails();
                    GetLeaders();
                    BindConvList();
                }

                // ELSE IF SESSION VARIABLE IS POPULATED
                else if (Session["UserID"] != null)
                {
                    GetOrgUserFromSession();
                    GetOrgDetails();
                    GetLeaders();
                    BindConvList();
                }

                else
                {
                    // ELSE IF NOT LOGGED IN NOR USING TOKEN NOR SESSION SEND TO DEFAULT PAGE
                    Response.Redirect("/Default.aspx");
                }
            }
        }