Пример #1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userData"></param>
        /// <param name="token"></param>
        public void SignIn(SortedList <string, string> userData, out string token)
        {
            token = null;
            var data = NHHIdentity.BuildString(userData);
            var type = ParamManager.GetStringValue("auth:type").ToUpper();

            switch (type)
            {
            case "NHH":
            {
                HttpContext.Current.Response.Headers[NHHAuthentication.NHHAuthHeaderName] = token = NHHAuthentication.Encrypt(data);
                this.User = new NHHPrincipal(new NHHIdentity("NHH", userData));
                break;
            }

            case "FROMS":
            {
                if (FormsAuthentication.IsEnabled)
                {
                    var ticket = new FormsAuthenticationTicket(1, userData["UserName"] ?? userData["UserID"], DateTime.Now, DateTime.Now.AddMinutes(120), false, data);
                    HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)));
                    this.User = new NHHPrincipal(new NHHIdentity("Froms", userData));
                }
                break;
            }

            case "NONE":
            default:
            {
                break;
            }
            }
        }
Пример #2
0
        protected void context_AuthenticateRequest(object sender, EventArgs e)
        {
            var type = ParamManager.GetStringValue("auth:type").ToUpper();

            switch (type)
            {
            case "NHH":
            {
                var head = HttpContext.Current.Request.Headers[NHHAuthentication.NHHAuthHeaderName];
                if (head != null)
                {
                    var ticket   = NHHAuthentication.Decrypt(head);
                    var identity = new NHHIdentity("NHH", ticket);
                    this.LoadUserConfig(identity.UserID);
                    var principal = new NHHPrincipal(identity, GetUserPermissions(identity.UserID));
                    NHHWebContext.Current.User = principal;
                }
                break;
            }

            case "FROMS":
            {
                if (FormsAuthentication.IsEnabled)
                {
                    var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                    if (cookie != null)
                    {
                        //登录用户主体信息
                        var ticket   = FormsAuthentication.Decrypt(cookie.Value);
                        var identity = new NHHIdentity("Forms", ticket.UserData);
                        this.LoadUserConfig(identity.UserID);
                        var principal = new NHHPrincipal(identity, GetUserPermissions(identity.UserID));
                        NHHWebContext.Current.User = principal;
                    }
                }
                break;
            }

            case "NONE":
            default:
            {
                break;
            }
            }
        }