mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 01:58:01 +08:00
采用全新的数据库架构
This commit is contained in:
72
Infrastructure/CookieHelper.cs
Normal file
72
Infrastructure/CookieHelper.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : Infrastructure
|
||||
// Author : Administrator
|
||||
// Created : 09-22-2015
|
||||
//
|
||||
// ***********************************************************************
|
||||
// <copyright file="CookieHelper.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>Cookie辅助</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
namespace Infrastructure.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Cookie帮助类
|
||||
/// </summary>
|
||||
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值
|
||||
/// </summary>
|
||||
/// <param name="strName">名称</param>
|
||||
/// <param name="strValue">值</param>
|
||||
/// <param name="strValue">过期时间(分钟)</param>
|
||||
public static void WriteCookie(string strName, string strValue, int expires)
|
||||
{
|
||||
HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
|
||||
if (cookie == null)
|
||||
{
|
||||
cookie = new HttpCookie(strName);
|
||||
}
|
||||
cookie.Value = strValue;
|
||||
cookie.Expires = DateTime.Now.AddMinutes(expires);
|
||||
HttpContext.Current.Response.AppendCookie(cookie);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读cookie值
|
||||
/// </summary>
|
||||
/// <param name="strName">名称</param>
|
||||
/// <returns>cookie值</returns>
|
||||
public static string GetCookie(string strName)
|
||||
{
|
||||
if (HttpContext.Current.Request.Cookies[strName] != null)
|
||||
{
|
||||
return HttpContext.Current.Request.Cookies[strName].Value.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user