/**/
/// <summary>
/// 写论坛cookie值
/// </summary>
/// <param name="strName">项</param>
/// <param name="strValue">值</param>
public static void WriteCookie( string strName, string strValue)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["dnt"];
if (cookie == null)
{
cookie = new HttpCookie("dnt");
cookie.Values[strName] = Utils.UrlEncode(strValue);
}
else
{
cookie.Values[strName] = Utils.UrlEncode(strValue);
if (HttpContext.Current.Request.Cookies["dnt"]["expires"] != null)
{
int expires = Utils.StrToInt(HttpContext.Current.Request.Cookies["dnt"]["expires"].ToString(), 0);
if (expires > 0)
{
cookie.Expires = DateTime.Now.AddMinutes(Utils.StrToInt(HttpContext.Current.Request.Cookies["dnt"]["expires"].ToString(), 0));
}
}
}
string cookieDomain = ConfigFactory.GetConfig().CookieDomain.Trim();
if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && IsValidDomain(HttpContext.Current.Request.Url.Host))
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
}
/**/ /// <summary>
/// 写cookie值
/// </summary>
/// <param name="strName">名称</param>
/// <param name="intValue">值</param>
public static void WriteCookie( string strName, int intValue)
{
WriteCookie(strName, intValue.ToString());
}
/**/ /// <summary>
/// 写论坛登录用户的cookie
/// </summary>
/// <param name="uid">用户名</param>
/// <param name="expires">cookie有效期</param>
/// <param name="passwordkey">用户密码Key</param>
/// <param name="templateid">用户当前要使用的界面风格</param>
/// <param name="invisible">用户当前的登录模式(正常或隐身)</param>
public static void WriteUserCookie( int uid, int expires, string passwordkey, int templateid, int invisible)
{
ShortUserInfo __userinfo = UserFactory.GetShortUserInfo(uid);
if (__userinfo != null)
{
HttpCookie cookie = new HttpCookie("dnt");
cookie.Values["userid"] = uid.ToString();
cookie.Values["password"] = Utils.UrlEncode(SetCookiePassword(__userinfo.Password, passwordkey));
if (TemplateFactory.GetTemplateItem(templateid) == null)
{
templateid = 0;
foreach(string strTemplateid in Utils.SplitString(TemplateFactory.GetValidTemplateIDList(), ","))
{
if (strTemplateid.Equals(__userinfo.Templateid.ToString()))
{
templateid = __userinfo.Templateid;
break;
}
}
}
cookie.Values["tpp"] = __userinfo.Tpp.ToString();
cookie.Values["ppp"] = __userinfo.Ppp.ToString();
cookie.Values["pmsound"] = __userinfo.Pmsound.ToString();
if (invisible != 0 || invisible != 1)
{
invisible = __userinfo.Invisible;
}
cookie.Values["invisible"] = invisible.ToString();
cookie.Values["referer"] = "index.aspx";
cookie.Values["sigstatus"] = __userinfo.Sigstatus.ToString();
cookie.Values["expires"] = expires.ToString();
if (expires > 0)
{
cookie.Expires = DateTime.Now.AddMinutes(expires);
}
string cookieDomain = ConfigFactory.GetConfig().CookieDomain.Trim();
if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && IsValidDomain(HttpContext.Current.Request.Url.Host))
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
Utils.WriteCookie("dnttemplateid", templateid.ToString(), 999999);
//SetCookieExpires(expires);
}
}
/**/ /// <summary>
/// 写论坛登录用户的cookie
/// </summary>
/// <param name="uid">用户名</param>
/// <param name="expires">cookie有效期</param>
/// <param name="passwordkey">用户密码Key</param>
public static void WriteUserCookie( int uid, int expires, string passwordkey)
{
WriteUserCookie(uid, expires, passwordkey, 0, -1);
}
/**/ /// <summary>
/// 获得论坛cookie值
/// </summary>
/// <param name="strName">项</param>
/// <returns>值</returns>
public static string GetCookie( string strName)
{
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies["dnt"] != null && HttpContext.Current.Request.Cookies["dnt"][strName] != null)
{
return Utils.UrlDecode(HttpContext.Current.Request.Cookies["dnt"][strName].ToString());
}
return "";
}
/**/ /// <summary>
/// 清除论坛登录用户的cookie
/// </summary>
public static void ClearUserCookie()
{
HttpCookie cookie = new HttpCookie("dnt");
cookie.Values.Clear();
cookie.Expires = DateTime.Now.AddYears(-1);
string cookieDomain = ConfigFactory.GetConfig().CookieDomain.Trim();
if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && IsValidDomain(HttpContext.Current.Request.Url.Host))
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
}
/// 写论坛cookie值
/// </summary>
/// <param name="strName">项</param>
/// <param name="strValue">值</param>
public static void WriteCookie( string strName, string strValue)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["dnt"];
if (cookie == null)
{
cookie = new HttpCookie("dnt");
cookie.Values[strName] = Utils.UrlEncode(strValue);
}
else
{
cookie.Values[strName] = Utils.UrlEncode(strValue);
if (HttpContext.Current.Request.Cookies["dnt"]["expires"] != null)
{
int expires = Utils.StrToInt(HttpContext.Current.Request.Cookies["dnt"]["expires"].ToString(), 0);
if (expires > 0)
{
cookie.Expires = DateTime.Now.AddMinutes(Utils.StrToInt(HttpContext.Current.Request.Cookies["dnt"]["expires"].ToString(), 0));
}
}
}
string cookieDomain = ConfigFactory.GetConfig().CookieDomain.Trim();
if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && IsValidDomain(HttpContext.Current.Request.Url.Host))
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
}
/**/ /// <summary>
/// 写cookie值
/// </summary>
/// <param name="strName">名称</param>
/// <param name="intValue">值</param>
public static void WriteCookie( string strName, int intValue)
{
WriteCookie(strName, intValue.ToString());
}
/**/ /// <summary>
/// 写论坛登录用户的cookie
/// </summary>
/// <param name="uid">用户名</param>
/// <param name="expires">cookie有效期</param>
/// <param name="passwordkey">用户密码Key</param>
/// <param name="templateid">用户当前要使用的界面风格</param>
/// <param name="invisible">用户当前的登录模式(正常或隐身)</param>
public static void WriteUserCookie( int uid, int expires, string passwordkey, int templateid, int invisible)
{
ShortUserInfo __userinfo = UserFactory.GetShortUserInfo(uid);
if (__userinfo != null)
{
HttpCookie cookie = new HttpCookie("dnt");
cookie.Values["userid"] = uid.ToString();
cookie.Values["password"] = Utils.UrlEncode(SetCookiePassword(__userinfo.Password, passwordkey));
if (TemplateFactory.GetTemplateItem(templateid) == null)
{
templateid = 0;
foreach(string strTemplateid in Utils.SplitString(TemplateFactory.GetValidTemplateIDList(), ","))
{
if (strTemplateid.Equals(__userinfo.Templateid.ToString()))
{
templateid = __userinfo.Templateid;
break;
}
}
}
cookie.Values["tpp"] = __userinfo.Tpp.ToString();
cookie.Values["ppp"] = __userinfo.Ppp.ToString();
cookie.Values["pmsound"] = __userinfo.Pmsound.ToString();
if (invisible != 0 || invisible != 1)
{
invisible = __userinfo.Invisible;
}
cookie.Values["invisible"] = invisible.ToString();
cookie.Values["referer"] = "index.aspx";
cookie.Values["sigstatus"] = __userinfo.Sigstatus.ToString();
cookie.Values["expires"] = expires.ToString();
if (expires > 0)
{
cookie.Expires = DateTime.Now.AddMinutes(expires);
}
string cookieDomain = ConfigFactory.GetConfig().CookieDomain.Trim();
if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && IsValidDomain(HttpContext.Current.Request.Url.Host))
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
Utils.WriteCookie("dnttemplateid", templateid.ToString(), 999999);
//SetCookieExpires(expires);
}
}
/**/ /// <summary>
/// 写论坛登录用户的cookie
/// </summary>
/// <param name="uid">用户名</param>
/// <param name="expires">cookie有效期</param>
/// <param name="passwordkey">用户密码Key</param>
public static void WriteUserCookie( int uid, int expires, string passwordkey)
{
WriteUserCookie(uid, expires, passwordkey, 0, -1);
}
/**/ /// <summary>
/// 获得论坛cookie值
/// </summary>
/// <param name="strName">项</param>
/// <returns>值</returns>
public static string GetCookie( string strName)
{
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies["dnt"] != null && HttpContext.Current.Request.Cookies["dnt"][strName] != null)
{
return Utils.UrlDecode(HttpContext.Current.Request.Cookies["dnt"][strName].ToString());
}
return "";
}
/**/ /// <summary>
/// 清除论坛登录用户的cookie
/// </summary>
public static void ClearUserCookie()
{
HttpCookie cookie = new HttpCookie("dnt");
cookie.Values.Clear();
cookie.Expires = DateTime.Now.AddYears(-1);
string cookieDomain = ConfigFactory.GetConfig().CookieDomain.Trim();
if (cookieDomain != string.Empty && HttpContext.Current.Request.Url.Host.IndexOf(cookieDomain) > -1 && IsValidDomain(HttpContext.Current.Request.Url.Host))
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
}