已知cookies  value值,如何得到cookies 的 name。

解决方案 »

  1.   

    知道index的话可以用page.Response.Cookies.GetKey(index),
    但是如果只知道value值的话只能for(int i=0;i<page.Response.Cookies.Count;i++)循环查找一下了,而且还要保证其他的cookies不会出现同样的值
      

  2.   

    现在只知道value值,做循环查的话,应该怎么写,能不能再多给点提示。
    value值是都唯一的。
      

  3.   

    int index = -1;
    for(int i=0;i<Page.Response.Cookies.Count;i++)
    {
       if(Page.Response.Cookies[i].Value == 你知道的值)
       { 
         index = i;
         break;
       }
    }
    if(index >-1)
    string cookieName = Page.Cookies.GetKey(index);
      

  4.   

    索引超出范围。必须为非负值并小于集合大小。参数名: index 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。参数名: index源错误: 
    行 258: for(int i=0;i<Request.Cookies.Count-1;i++)
    行 259: {
    行 260: if(Response.Cookies[i].Value == aaa)
    行 261: {
    行 262:
     
      

  5.   

    行 258: for(int i=0;i<Request.Cookies.Count-1;i++)
    行 259: {
    行 260: if(Response.Cookies[i].Value == aaa)
    行 261: {
    行 262:
     
    一会是Request. 一会是Response. 当然出错啦~~