Ejemplo n.º 1
0
 public static dynamic GetCurrentCountryAndLang()
 {
     try
     {
         if (MvcContext.GetContext().Request.Path.Value.ToLower().ToString().Contains("/home/error"))
         {
             return(new { Country = "us", Language = "en" });
         }
         //string regex = @"(?<=^/)([x]{1}|[a-z]{2,})_(([\w-]+(?=/))|[\w-]{5})";
         string regex    = @"(?<=^/)([x]{1}|[a-z]{2,})_(([\w-]{2}-[\w-]{2})|([\w-]{2,3}))";
         Match  lac      = Regex.Match(MvcContext.GetContext().Request.Path, regex);//获取到国家和语言
         string regexalc = @"[^_]+";
         var    lacarr   = Regex.Matches(lac.ToString(), regexalc);
         return(new { Country = lacarr[0].ToString().ToLower(), Language = lacarr[1].ToString().ToLower() });
     }
     catch (Exception ex)
     {
         LogHelper.Error("获取地址栏国家和语言出错" + ex.Message + ex.StackTrace + "当前地址:" + MvcContext.GetContext().Request.Host + MvcContext.GetContext().Request.Path);
         return(new { Country = "us", Language = "en" });
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 删除指定的cookie
 /// </summary>
 /// <param name="key">键</param>
 public static void DeleteCookies(string key)
 {
     MvcContext.GetContext().Response.Cookies.Delete(key);
 }