Hotel/Common/CookieHelper.cs
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Text.RegularExpressions;
namespace Common
{
public class CookieHelper
{
/// <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[strName];
if (cookie == null)
{
cookie = new HttpCookie(strName);
}
cookie.Value = strValue;
HttpContext.Current.Response.AppendCookie(cookie);
}
/// <summary>
/// 寫cookie值,在客戶端建立文件。存放cookie值(單一項值)。
/// </summary>
/// <param name="strName">名稱</param>
/// <param name="strValue">值</param>
/// <param name="cookieDomain">域</param>
/// <param name="expires">cookie 保存時長 單位分種</param>
public static void WriteCookie(string strName, string strValue, string cookieDomain, int expires)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[strName] ?? new HttpCookie(strName);
cookie.Value = strValue;
//cookie.Expires = DateTime.Now.AddMinutes(expires);
cookie.Expires = DateTime.Now.AddMinutes(expires);
cookie.Domain = cookieDomain;
HttpContext.Current.Response.AppendCookie(cookie);
}
/// <summary>
/// 寫cookie值(存放數組形式參數,用於第一次寫cookie值,並指定有效時間)
/// </summary>
/// <param name="cookieName">cookies名字</param>
/// <param name="strValuesName">cookie項的名稱,cookie[strValuesName][]</param>
/// <param name="strValue">cookie項的值,cookie[strValuesName][strValue]</param>
/// <param name="cookieDomain">cookie域屬性</param>
/// <param name="expiresDays">cookies 有效時間 單位天</param>
public static void WriteCookie(string cookieName, string strValuesName, string strValue, string cookieDomain, int expiresDays)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
if (cookie == null)
{
cookie = new HttpCookie(cookieName);
cookie.Values[strValuesName] = HttpUtility.UrlEncode(strValue);
后面还有 120 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。