using System; using System.Web; namespace Quiz.SiteBase { public class SiteHelper { /// /// 当前登录用户 /// public static string UserId { get { try { return Utility.Helper.DESDeCode(UserCookie[SiteContant.CookieKey.UserCode], SiteContant.CookieKey.UserKey); } catch (Exception) { return ""; } } set { SetUidCookie(value); } } public static string CurrentUrl { get { return string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, HttpContext.Current.Request.RawUrl); } } #region UserCookie ///// ///// Cookie域 ///// //public static string CookieDomain //{ // get // { // var domain = HttpContext.Current.Request.Url.Host.StartsWith("60.190") ? "60.190.202.41" : Common.Config.RootURL; // return IsLocal ? null : domain; // } //} /// /// 客户端操作Cookie /// public static HttpCookie UserCookie { get { HttpCookie httpcookie = SiteCookie.GetCookies(SiteContant.CookieKey.UserInfo); if (httpcookie == null) { httpcookie = new HttpCookie(SiteContant.CookieKey.UserInfo); //httpcookie.Domain = CookieDomain; SiteCookie.SaveCookie(httpcookie, 3600); } //else httpcookie.Domain = CookieDomain; return httpcookie; } } //设置用户的Cookie public static void SetUidCookie(string value) { string key = string.IsNullOrEmpty(value) ? value : Utility.Helper.DESEnCode(value, SiteContant.CookieKey.UserKey); UserCookie.Values[SiteContant.CookieKey.UserCode] = key; SiteCookie.SaveCookie(UserCookie, 3600); } //设置用户的Cookie public static void SetUidCookie(string key, string value) { UserCookie.Values[key] = value; SiteCookie.SaveCookie(UserCookie, 3600); } #endregion } }