Exemple #1
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            try
            {
                PayNet.Online.Web.Security.CheckSession(System.Web.HttpContext.Current);
            }
            catch
            {
                // Get the redirection URL for the request from the system.web/authentication section in the the web.config.
                var authenticationSection = (System.Web.Configuration.AuthenticationSection)System.Configuration.ConfigurationManager.GetSection("system.web/authentication");
                System.Web.Configuration.FormsAuthenticationConfiguration formsAuthentication = authenticationSection.Forms;
                string currentLoginUrl = formsAuthentication.LoginUrl;

                HttpContext.Current.Response.Redirect(currentLoginUrl, true);
            }
        }
Exemple #2
0
        public string VerifyUser(string username, string password, string appcode)
        {
            System.Web.Security.FormsAuthentication.SetAuthCookie(username, true);
            // 创建验证票
            System.Web.Configuration.FormsAuthenticationConfiguration formsConfig = new System.Web.Configuration.FormsAuthenticationConfiguration();
            FormsAuthenticationTicket formAuthTicket = new
                                                       FormsAuthenticationTicket(
                1,                                                         // 版本
                username,                                                  // 用户名称
                DateTime.Now,                                              // 创建时间
                DateTime.Now.AddMinutes(formsConfig.Timeout.TotalMinutes), // 失效时间
                true, "");                                                 // 用户数据

            //加密票
            string encryptedTicket = FormsAuthentication.Encrypt(formAuthTicket);
            // 以加密票的密文存入Cookie
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            authCookie.HttpOnly = true;
            authCookie.Path     = FormsAuthentication.FormsCookiePath;
            authCookie.Secure   = FormsAuthentication.RequireSSL;
            if (FormsAuthentication.CookieDomain != null)
            {
                authCookie.Domain = FormsAuthentication.CookieDomain;
            }
            if (formAuthTicket.IsPersistent)
            {
                authCookie.Expires = formAuthTicket.Expiration;
            }

            HttpContext.Current.Response.Cookies.Add(authCookie);
            FormsIdentity    identity  = new FormsIdentity(formAuthTicket);
            GenericPrincipal principal = new GenericPrincipal(identity, null);

            HttpContext.Current.User = principal;


            return("");
        }
Exemple #3
0
        public string VerifyUser(string username, string password, string appcode)
        {
            System.Web.Security.FormsAuthentication.SetAuthCookie(username, true);
            // 创建验证票
            System.Web.Configuration.FormsAuthenticationConfiguration formsConfig = new System.Web.Configuration.FormsAuthenticationConfiguration();
            FormsAuthenticationTicket formAuthTicket = new
                FormsAuthenticationTicket(
                        1,                              // 版本
                        username,                          // 用户名称
                        DateTime.Now,                   // 创建时间
                        DateTime.Now.AddMinutes(formsConfig.Timeout.TotalMinutes),    // 失效时间
                        true, "");    // 用户数据

            //加密票
            string encryptedTicket = FormsAuthentication.Encrypt(formAuthTicket);
            // 以加密票的密文存入Cookie
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            authCookie.HttpOnly = true;
            authCookie.Path = FormsAuthentication.FormsCookiePath;
            authCookie.Secure = FormsAuthentication.RequireSSL;
            if (FormsAuthentication.CookieDomain != null)
            {
                authCookie.Domain = FormsAuthentication.CookieDomain;
            }
            if (formAuthTicket.IsPersistent)
            {
                authCookie.Expires = formAuthTicket.Expiration;
            }

            HttpContext.Current.Response.Cookies.Add(authCookie);
            FormsIdentity identity = new FormsIdentity(formAuthTicket);
            GenericPrincipal principal = new GenericPrincipal(identity, null);
            HttpContext.Current.User = principal;


            return "";
            
        }