public static DomainAttributes GetClient(Uri url, string subdomain)
        {
            DomainAttributes Dm = new DomainAttributes();

            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            url = GetUrl(url, IsLive, false);

            Dm = SplitUrl(url, subdomain);

            return(Dm);
        }
        public static AdminDomainAttributes AdminGetClient(Uri url)
        {
            AdminDomainAttributes Dm = new AdminDomainAttributes();

            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            url = GetUrl(url, IsLive, true);

            Dm = AdminSplitUrl(url);

            return(Dm);
        }
        public static bool ClientIsValid1(Uri url)
        {
            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            url = GetUrl(url, IsLive, false);
            bool   result   = false;
            string host     = url.Host;
            int    dmLength = host.Split('.').Length;

            string query = "Select id,Name from cc_masterdataset.customer where SubDomainName='";

            switch (dmLength)
            {
            case 3:
                query += host.Split('.')[0] + "' AND Parent='SELF'";
                break;

            case 4:
                query += host.Split('.')[0] + "' AND Parent='" + host.Split('.')[1] + "'";
                break;

            default:
                myredirect("Not in Use");
                break;
            }


            SqlConnection conn = new SqlConnection(DBConnectionString());

            conn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd = new SqlCommand(query, conn);
            SqlDataReader rd = cmd.ExecuteReader();

            rd.Read();
            if (rd.HasRows)
            {
                result = true;
            }
            else
            {
                myredirect("Not in Use");
                result = false;
            }
            conn.Close();

            return(result);
        }
        public static bool AdminClientIsValid(Uri url)
        {
            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            url = GetUrl(url, IsLive, true);
            bool   result   = false;
            string host     = url.Host;
            int    dmLength = host.Split('.').Length;

            if (host.Split('.')[0].ToString() != "www")
            {
                string query = "Select id,Name from cc_masterdataset.customer where SubDomainName='";


                switch (dmLength)
                {
                case 3:
                    query += host.Split('.')[0] + "' AND Parent='SELF'";
                    break;

                default:
                    myredirect("Invalid Url Contact Administration.");
                    break;
                }

                SqlConnection conn = new SqlConnection(DBConnectionString());
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = new SqlCommand(query, conn);
                SqlDataReader rd = cmd.ExecuteReader();
                rd.Read();
                if (rd.HasRows)
                {
                    result = true;
                }
                else
                {
                    myredirect("Invalid Url Contact Administration.");
                    result = false;
                }
                conn.Close();
            }
            else
            {
                HttpContext.Current.Response.Redirect("http://" + host.Replace("www.", "").ToString() + "/Login.aspx");
            }

            return(result);
        }
        public static void rewriteurl(Uri url)
        {
            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            bool mode = false;

            url = GetUrl(url, IsLive, false);
            bool   result   = false;
            string host     = url.Host;
            int    dmLength = host.Split('.').Length;

            if (host.Split('.')[0].ToString() != "www")
            {
                string query = "Select id,Name from cc_masterdataset.customer where SubDomainName='";

                switch (dmLength)
                {
                case 3:
                    query += host.Split('.')[0] + "' AND Parent='SELF'";
                    mode   = false;
                    break;

                case 4:
                    query += host.Split('.')[0] + "' AND Parent='" + host.Split('.')[1] + "'";
                    mode   = true;
                    break;

                default:
                    myredirect("Not in Use");
                    break;
                }


                SqlConnection conn = new SqlConnection(DBConnectionString());
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = new SqlCommand(query, conn);
                SqlDataReader rd = cmd.ExecuteReader();
                rd.Read();
                if (rd.HasRows)
                {
                    result = true;
                }
                else
                {
                    myredirect("Not in Use");
                    result = false;
                }
                conn.Close();

                if (result)
                {
                    if (mode)
                    {
                        reseturl(IsLive, host.Split('.')[1], host.Split('.')[0], mode);
                    }
                    else
                    {
                        reseturl(IsLive, host.Split('.')[0], "", mode);
                    }
                }
            }
            else
            {
                //HttpContext.Current.Response.Redirect("http://" + host.Replace("www.","").ToString());
                //HttpContext.Current.Response.Redirect("~/Urlcheck.aspx");
                HttpContext.Current.Response.Redirect("http://www.credentialconsultants.com/");
            }
        }
        public static bool ClientIsValid(Uri url, string subdomain)
        {
            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            url = GetUrl(url, IsLive, false);
            bool   result   = false;
            string host     = url.Host;
            int    dmLength = host.Split('.').Length;
            string sQuery   = url.Query;

            if (sQuery.Contains("subdomain="))
            {
                subdomain = HttpUtility.ParseQueryString(sQuery).Get("subdomain");
            }
            else
            {
                subdomain = "";
            }



            if (System.Configuration.ConfigurationSettings.AppSettings["Test"].ToString() == "1")
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write(url + "-Invalid Url");
                HttpContext.Current.Response.End();
            }
            if (!subdomain.Contains("www"))
            {
                string query = "Select id,Name from cc_masterdataset.customer where";

                if (subdomain == "")
                {
                    query += " SubDomainName='" + host.Split('.')[0] + "' AND Parent='SELF'";
                }
                else
                {
                    query += " SubDomainName='" + subdomain + "' AND Parent='" + host.Split('.')[0] + "'";
                }

                SqlConnection conn = new SqlConnection(DBConnectionString());
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = new SqlCommand(query, conn);
                SqlDataReader rd = cmd.ExecuteReader();
                rd.Read();
                if (rd.HasRows)
                {
                    result = true;
                }
                else
                {
                    myredirect(url.ToString());
                    result = false;
                }
                conn.Close();
            }
            else
            {
                string domain = host.Split('.')[0];
                if ((!subdomain.Contains("www.")) || (subdomain == ""))
                {
                    HttpContext.Current.Response.Redirect("https://" + domain + ".credentialconnection.com/Default.aspx");
                }
                else
                {
                    // HttpContext.Current.Response.Redirect("http://" + host.Replace("www.", "").ToString());
                    // HttpContext.Current.Response.Redirect("~/Urlcheck.aspx");
                    HttpContext.Current.Response.Redirect("https://" + domain + ".credentialconnection.com/Default.aspx?subdomain=" + subdomain.Replace("www.", "").ToString());
                }
            }
            return(result);
        }
        public static bool ClientIsValid2(Uri url, string subdomain)
        {
            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();
            bool IsLive = Convert.ToBoolean(app.TypeSwitcher);

            url = GetUrl(url, IsLive, false);
            bool   result   = false;
            string host     = url.Host;
            int    dmLength = host.Split('.').Length;

            if (host.Split('.')[0].ToString() != "www")
            {
                string query = "Select id,Name from cc_masterdataset.customer where";

                if (subdomain == "nosubdomain")
                {
                    query += " SubDomainName='" + host.Split('.')[0] + "' AND Parent='SELF'";
                }
                else
                {
                    query += " SubDomainName='" + subdomain + "' AND Parent='" + host.Split('.')[0] + "'";
                }



                //switch (dmLength)
                //{
                //    case 3:
                //        query += host.Split('.')[0] + "' AND Parent='SELF'";
                //        break;
                //    case 4:
                //        query += host.Split('.')[0] + "' AND Parent='" + host.Split('.')[1] + "'";
                //        break;
                //    default:
                //        myredirect();
                //        break;
                //}


                SqlConnection conn = new SqlConnection(DBConnectionString());
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = new SqlCommand(query, conn);
                SqlDataReader rd = cmd.ExecuteReader();
                rd.Read();
                if (rd.HasRows)
                {
                    result = true;
                }
                else
                {
                    myredirect("Not in Use");
                    result = false;
                }
                conn.Close();
            }
            else
            {
                // HttpContext.Current.Response.Redirect("http://" + host.Replace("www.", "").ToString());
                // HttpContext.Current.Response.Redirect("~/Urlcheck.aspx");
                HttpContext.Current.Response.Redirect("http://www.credentialconsultants.com/");
            }
            return(result);
        }
        public static string GetSubDomain(string Name, string Password, Uri url, string type)
        {
            RossSoft.Utility.AppConfig app = RossSoft.Utility.AppSettings();

            bool   block         = false; //Convert.ToBoolean(app.TypeSwitcher);
            string SubDomainName = "";
            string title         = "";

            if (block)
            {
                //---main block--------------------------------------------
                string host = url.Host;
                if (host.Split('.').Length > 1)
                {
                    int index = host.IndexOf(".");
                    SubDomainName = host.Substring(0, index);
                    switch (type)
                    {
                    case "title":
                        title = Check_Title(SubDomainName);
                        bool Isvalid = Authentication.Utility.Getcompanylist(title);

                        if (!Isvalid)
                        {
                            HttpContext.Current.Response.Redirect("http://www.credentialconsultants.com/");
                        }

                        break;

                    case "check_customer":
                        int cstid = Check_Customer(SubDomainName);
                        title = cstid.ToString();
                        break;

                    case "login":
                        string result = Login(Name, Password, SubDomainName);
                        title = result;
                        break;
                    }
                    return(title);
                }
                //---main block--------------------------------------------
            }
            else
            {
                //---demo block--------------------------------------------
                SubDomainName = "ravtronix";
                switch (type)
                {
                case "title":
                    title = Check_Title(SubDomainName);
                    break;

                case "check_customer":
                    int cstid = Check_Customer(SubDomainName);
                    title = cstid.ToString();
                    break;

                case "login":
                    string result = Login(Name, Password, SubDomainName);
                    title = result;
                    break;
                }
                return(title);


                //---demo block--------------------------------------------
            }

            return(null);
        }