Ejemplo n.º 1
0
        /// <summary>
        /// 重写  控制器的 action 执行方法
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            //注意 web api 在本设计中 ,不让设置 页面标识 Cookie 。增加这个Cookie 是为了防止采集和蜘蛛
            if (context.Controller is BaseApiController)
            {
                base.OnActionExecuting(context);
                return;
            }

            //1监测是否有了必须的Cookie标识  如果没有 那么追加
            var cookieWebbrowserSign = context.HttpContext.GetCookie <string>(Contanst.Cookie_Key_BrowserSign);

            if (string.IsNullOrEmpty(cookieWebbrowserSign))
            {
                cookieWebbrowserSign = string.Concat(WorkContext.SiteName, "|", DateTime.Now.ToOfenTimeString());
                string encodedSign = LZString.Compress(cookieWebbrowserSign, true);
                //将加密后的cookie  写入到响应客户端
                string domain = null;
                //string webStatus = ConfigHelper.AppSettingsConfiguration.GetConfig("WebStatus");
                //判断是否为正式环境
                if (WorkContext.HostingEnvironment.IsProduction())
                {
                    //正式环境cookie 过期为1天
                    domain = Contanst.Global_Site_Domain_Cookie;
                    context.HttpContext.SetCookie <string>(domain, Contanst.Cookie_Key_BrowserSign, encodedSign, 1, true);
                }
                else
                {
                    //测试环境 cookie 不过期
                    context.HttpContext.SetCookie <string>(domain, Contanst.Cookie_Key_BrowserSign, encodedSign, true);
                }
            }
            base.OnActionExecuting(context);
        }
Ejemplo n.º 2
0
            public static String CompressToUTF16(String input)
            {
                if (input == null)
                {
                    return("");
                }
                String output = "";
                int    c;
                int    current = 0;
                int    status  = 0;

                input = LZString.Compress(input);

                for (int i = 0; i < input.Length; i++)
                {
                    c = (int)input[i];
                    switch (status++)
                    {
                    case 0:
                        output += (char)((c >> 1) + 32);
                        current = (c & 1) << 14;
                        break;

                    case 1:
                        output += (char)((current + (c >> 2)) + 32);
                        current = (c & 3) << 13;
                        break;

                    case 2:
                        output += (char)((current + (c >> 3)) + 32);
                        current = (c & 7) << 12;
                        break;

                    case 3:
                        output += (char)((current + (c >> 4)) + 32);
                        current = (c & 15) << 11;
                        break;

                    case 4:
                        output += (char)((current + (c >> 5)) + 32);
                        current = (c & 31) << 10;
                        break;

                    case 5:
                        output += (char)((current + (c >> 6)) + 32);
                        current = (c & 63) << 9;
                        break;

                    case 6:
                        output += (char)((current + (c >> 7)) + 32);
                        current = (c & 127) << 8;
                        break;

                    case 7:
                        output += (char)((current + (c >> 8)) + 32);
                        current = (c & 255) << 7;
                        break;

                    case 8:
                        output += (char)((current + (c >> 9)) + 32);
                        current = (c & 511) << 6;
                        break;

                    case 9:
                        output += (char)((current + (c >> 10)) + 32);
                        current = (c & 1023) << 5;
                        break;

                    case 10:
                        output += (char)((current + (c >> 11)) + 32);
                        current = (c & 2047) << 4;
                        break;

                    case 11:
                        output += (char)((current + (c >> 12)) + 32);
                        current = (c & 4095) << 3;
                        break;

                    case 12:
                        output += (char)((current + (c >> 13)) + 32);
                        current = (c & 8191) << 2;
                        break;

                    case 13:
                        output += (char)((current + (c >> 14)) + 32);
                        current = (c & 16383) << 1;
                        break;

                    case 14:
                        output += (char)((current + (c >> 15)) + 32);
                        output += (char)((c & 32767) + 32);

                        status = 0;
                        break;
                    }
                }

                output += (char)(current + 32);

                return(output);
            }
Ejemplo n.º 3
0
 public void Compress(LZStringTestCase test)
 {
     Assert.That(LZString.Compress(test.Uncompressed), Is.EqualTo(test.Compressed));
 }