using System; using System.Web; using System.Web.Security; namespace DSWeb.TruckMng.Comm.Cookie { public class CookieConfig { #region 设置Cookie static public void SetCookie(HttpRequestBase request, HttpResponseBase response, string cookiename, string value) { if (request.Browser.Cookies == true) { if (request.Cookies[cookiename] == null) { HttpCookie useridCookie = new HttpCookie(cookiename, HttpUtility.UrlEncode(value)); useridCookie.Expires = DateTime.Now.AddYears(1); useridCookie.Path = FormsAuthentication.FormsCookiePath; response.Cookies.Add(useridCookie); } else { response.Cookies.Remove(cookiename); HttpCookie useridCookie = new HttpCookie(cookiename, HttpUtility.UrlEncode(value)); useridCookie.Expires = DateTime.Now.AddYears(1); useridCookie.Path = FormsAuthentication.FormsCookiePath; response.Cookies.Add(useridCookie); } } } static public void RemoveCookie(HttpResponseBase response,string cookiename) { response.Cookies.Remove(cookiename); HttpCookie cookie = new HttpCookie(cookiename); cookie.Path = FormsAuthentication.FormsCookiePath; cookie.Value = null; cookie.Expires = DateTime.Now.AddDays(-1); response.Cookies.Add(cookie); } static public void RemoveAllPosCookies(HttpResponseBase response) { RemoveCookie(response,CookieConstant.Roles); RemoveCookie(response, CookieConstant.UserId); RemoveCookie(response, CookieConstant.UserCode); RemoveCookie(response, CookieConstant.UserName); RemoveCookie(response, CookieConstant.LocalCurr); RemoveCookie(response, CookieConstant.OrgName); RemoveCookie(response, CookieConstant.OrgYwStatus); RemoveCookie(response, CookieConstant.OrgType); RemoveCookie(response, CookieConstant.ZbOrgCode); RemoveCookie(response, CookieConstant.InOrgCode); RemoveCookie(response, CookieConstant.PosNo); RemoveCookie(response, CookieConstant.RunDate); RemoveCookie(response, CookieConstant.CompanyId); RemoveCookie(response, CookieConstant.ISSALEWORK); } //static public void SetSecurityInfoToCookie(HttpRequestBase request, HttpResponseBase response, SecurityInfo info) //{ // SetCookie(request, response, CookieConstant.UserId, info.UserId.ToString()); // SetCookie(request, response, CookieConstant.UserCode, info.UserCode); // SetCookie(request, response, CookieConstant.UserName, info.UserName); // SetCookie(request, response, CookieConstant.OrgCode, info.OrgCode); // SetCookie(request, response, CookieConstant.OrgName, info.OrgName); // SetCookie(request, response, CookieConstant.InOrgCode, info.InOrgCode); // SetCookie(request, response, CookieConstant.ZbOrgCode, info.ZbOrgCode); // SetCookie(request, response, CookieConstant.OrgYwStatus, info.OrgStatus); // SetCookie(request, response, CookieConstant.OrgType, info.OrgType); // SetCookie(request, response, CookieConstant.PosNo, "0000"); //} #endregion #region 取得Cookie static public string GetCookie(HttpRequestBase request, string cookiename) { HttpCookie cookie = request.Cookies[cookiename]; if (cookie == null) return String.Empty; return HttpUtility.UrlDecode(cookie.Value); } static public string GetCookie_UserId(HttpRequestBase request) { return GetCookie(request, CookieConstant.UserId); } static public string GetCookie_UserCode(HttpRequestBase request) { return GetCookie(request, CookieConstant.UserCode); } static public string GetCookie_UserName(HttpRequestBase request) { return GetCookie(request, CookieConstant.UserName); } static public string GetCookie_OrgCode(HttpRequestBase request) { return GetCookie(request, CookieConstant.OrgCode); } static public string GetCookie_LocalCurr(HttpRequestBase request) { return GetCookie(request, CookieConstant.LocalCurr); } static public string GetCookie_OrgName(HttpRequestBase request) { return GetCookie(request, CookieConstant.OrgName); } static public string GetCookie_InOrgCode(HttpRequestBase request) { return GetCookie(request, CookieConstant.InOrgCode); } static public string GetCookie_ZbOrgCode(HttpRequestBase request) { return GetCookie(request, CookieConstant.ZbOrgCode); } static public string GetCookie_OrgStatus(HttpRequestBase request) { return GetCookie(request, CookieConstant.OrgYwStatus); } static public string GetCookie_PosNo(HttpRequestBase request) { return GetCookie(request, CookieConstant.PosNo); } static public string GetCookie_OrgType(HttpRequestBase request) { return GetCookie(request, CookieConstant.OrgType); } static public string GetCookie_CompanyId(HttpRequestBase request) { return GetCookie(request, CookieConstant.CompanyId); } static public string GetCookie_ISSALEWORK(HttpRequestBase request) { return GetCookie(request, CookieConstant.ISSALEWORK); } #endregion } }