Exemple #1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            //Perform your logic here
            try
            {
                //actionContext.RequestContext.s
                string privilegeLevels = "";
                if (HttpContext.Current.Session["Role"] != null)
                {
                    privilegeLevels = HttpContext.Current.Session["Role"].ToString();
                }
                // string.Join("", GetUserRights(httpContext.User.Identity.Name.ToString())); // Call another method to get rights of the user from DB

                if (privilegeLevels == this.AccessLevel)
                {
                    base.OnAuthorization(actionContext);
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                NsUtility.SaveException(ex);
            }
        }
Exemple #2
0
 public static void SaveException(Exception ex)
 {
     try
     {
         NsUtility.SaveException(ex, Utility.GetIPAddress(), "NscBackOffice", Utility.GetCurrentUser().ID);
     }
     catch
     {
     }
 }
Exemple #3
0
        public static User GetCurrentUser()
        {
            User _user = new User();

            try
            {
                _user.ID = 1;
            }
            catch (Exception ex)
            {
                NsUtility.SaveException(ex);
            }

            return(_user);
        }
Exemple #4
0
        public static string GetIPAddress()
        {
            try
            {
                HttpContext context   = HttpContext.Current;
                string      ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

                if (!string.IsNullOrEmpty(ipAddress))
                {
                    string[] addresses = ipAddress.Split(',');
                    if (addresses.Length != 0)
                    {
                        return(addresses[0]);
                    }
                }

                return(context.Request.ServerVariables["REMOTE_ADDR"]);
            }
            catch (Exception ex)
            {
                NsUtility.SaveException(ex);
            }
            return("");
        }