public static bool IsValid(HttpCookie userCookie, HttpCookie fedAuth, Uri referer)
        {
            try
            {
                //get cookie sp
                //var userCookie = (HttpContext.Request.Cookies.Get("sp") != null) ? HttpContext.Request.Cookies.Get("sp") : null;
                if (userCookie == null)
                {
                    return(false);
                }

                var usernameCookie = Decrypt(userCookie.Value);

                //get cookie fedAuth
                //var fedAuth = HttpContext.Request.Cookies.Get("FedAuth");
                var fedAuthCookie = new Cookie()
                {
                    Expires = fedAuth.Expires,
                    Name    = fedAuth.Name,
                    Path    = fedAuth.Path,
                    Secure  = fedAuth.Secure,
                    Value   = String.IsNullOrEmpty(fedAuth.Value) ? "" : fedAuth.Value.Replace(' ', '+')
                };
                var cookies = new List <Cookie> {
                    fedAuthCookie
                };
                //string host = "http://portal.trakindo.co.id";
                string protokol = HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://";
                //var host = protokol + Host;
                string host            = protokol + ConfigurationManager.AppSettings["Host"];
                string accountId       = SharepointHelper.GetAccountAndId(host, @"application/atom+xml", cookies);
                var    usernameFedAuth = accountId.Split('|')[0];

                //cek if exist
                if (usernameCookie.Trim().ToLower() != usernameFedAuth.Trim().ToLower())
                {
                    return(false);
                }
                else
                {
                    // TODO: prepare spuser properties
                    //SharePointUser spUser = new SharePointUser(userLogin, "", "", userGroups.Distinct().ToList());

                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public static string GetUserXupj()
        {
            string xupj = "";

            if (WebConfigure.GetLoginPortal() == "false")
            {
                xupj = WebConfigure.GetLoginManualXupj();
            }
            else
            {
                try
                {
                    var        referer    = HttpContext.Current.Request.UrlReferrer;
                    HttpCookie userCookie = (HttpContext.Current.Request.Cookies.Get("sp") != null) ? HttpContext.Current.Request.Cookies.Get("sp") : null;
                    HttpCookie fedAuth    = HttpContext.Current.Request.Cookies.Get("FedAuth");
                    if (fedAuth != null)
                    {
                        fedAuth.Value = fedAuth.Value.Replace("%2B", "+");
                    }
                    var isValid = SharepointHelper.IsValid(userCookie, fedAuth, referer);
                    if (isValid)
                    {
                        string hostLogin = WebConfigure.GetLoginHost();
                        string protokol  = HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://";
                        var    host      = protokol + hostLogin;
                        var    userId    = SharepointHelper.GetUserId(host, @"application/atom+xml", fedAuth);
                        xupj = userId;
                    }
                }
                catch (Exception er)
                {
                    LogErrorBService.WriteLog("Common", MethodBase.GetCurrentMethod().Name, er.ToString());
                    HttpContext.Current.Response.Cookies.Remove("sp");
                    HttpContext.Current.Response.Cookies.Remove("FedAuth");
                    throw;
                }
            }
            return(xupj);
        }