没明白你的意思,但无非是以下两种情况:
1、你要在你的网页上执行脚本来读取本地Cookies这个简单,用document.cookie就行了。2、你想写个程序,读取当前硬盘中的所有Cookie内容。这个是不可能的,因为里面涉及到隐私问题,所有信息都是加密的,只有指定域的代码才能访问。但是万事没有绝对,我可以给你一个思路,但实现的难度是很大的。
1、写一个IE插件,当有访问网络时直接截取Cookies
2、写一个网络代理,这样当有http访问通过你的代理服务器的时候,你想截取什么就截取什么了。原理:http在传输进使用的是明文传递。、
1、你要在你的网页上执行脚本来读取本地Cookies这个简单,用document.cookie就行了。2、你想写个程序,读取当前硬盘中的所有Cookie内容。这个是不可能的,因为里面涉及到隐私问题,所有信息都是加密的,只有指定域的代码才能访问。但是万事没有绝对,我可以给你一个思路,但实现的难度是很大的。
1、写一个IE插件,当有访问网络时直接截取Cookies
2、写一个网络代理,这样当有http访问通过你的代理服务器的时候,你想截取什么就截取什么了。原理:http在传输进使用的是明文传递。、
using System.Configuration;
using System.Web;namespace SilenceZT.Cookie//空间名
{
public class OperationCookie //类名
{ /// <summary>
/// 判断是否有这个Cookie名称
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool checkCookie(string name)
{
if (System.Web.HttpContext.Current.Request.Cookies[name] == null)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 读取Cookie值
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string getCookie(string name)
{
if (System.Web.HttpContext.Current.Request.Cookies[name] == null)
{
return null;
}
else
{
return System.Web.HttpContext.Current.Request.Cookies[name].Value;
}
} /// <summary>
/// 读取Cookie - subCookie 值
/// </summary>
/// <param name="name"></param>
/// <param name="subname"></param>
/// <returns></returns>
public static string getCookie(string name, string subname)
{
if ((name != null) || (subname != null))
{
if (System.Web.HttpContext.Current.Request.Cookies[name] == null)
{
return null;
}
else
{
return System.Web.HttpContext.Current.Request.Cookies[name][subname];
}
}
else
{
return null;
}
} /// <summary>
/// 创建新Cookie
/// </summary>
/// <param name="strname"></param>
/// <param name="strvalue"></param>
/// <param name="intdate"></param>
public static void setCookie(string strname, string strvalue, int intdate)
{
try
{
System.Web.HttpCookie cookie = new HttpCookie(strname, strvalue);
cookie.Expires = DateTime.Now.AddDays(intdate);
System.Web.HttpContext.Current.Response.AppendCookie(cookie); //写入Cookie
}
catch (Exception e)
{
throw e; //抛出异常
}
} /// <summary>
/// 创建新子Cookie
/// </summary>
/// <param name="strname"></param>
/// <param name="strsubname"></param>
/// <param name="strvalue"></param>
public static void setSubCookie(string strname, string strsubname, string strvalue)
{
try
{
if (System.Web.HttpContext.Current.Request.Cookies[strname] != null)
{
System.Web.HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[strname];
cookie.Values.Set(strsubname, strvalue);
System.Web.HttpContext.Current.Request.Cookies.Set(cookie);
System.Web.HttpContext.Current.Response.AppendCookie(cookie);
}
}
catch (Exception e)
{
throw e;
}
} /// <summary>
/// 删除Cookie
/// </summary>
/// <param name="strname"></param>
public static void delCookie(string strname)
{
if (System.Web.HttpContext.Current.Request.Cookies[strname] != null)
{
System.Web.HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[strname];
cookie.Expires = DateTime.Now;
System.Web.HttpContext.Current.Response.AppendCookie(cookie);
}
} }}
闲的无聊写的希望对你有帮助,记得给分哦
虽然IE等能读取cookie值,
但你可能是想直接用程序读取硬盘中的cookie文件,然后打开此文件,再读取其中内容.对web程序来说,如果不在IIS目录下,你想进行读文件操作,应该是没有"权限"的.要不然,网站岂不是可以随意读取用户的硬盘文件?