在asp.net中读取Cookie值 [英] Read Cookie Value in asp.net

查看:202
本文介绍了在asp.net中读取Cookie值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Techies,

我的应用程序中有一个要求,我需要从其他应用程序创建的浏览器中读取Cookie.我无法读取Cookie值. Cookie是会话cookie,当浏览器丢失会话时,该cookie将会过期.我使用以下代码在浏览器中读取了所有cookie.但是,我找不到想要的Cookie.

Hi Techies,

I have a requirement in my application that i need to read a cookie from the browser which is created by the other application. I am not able to read the cookie value. The cookie is a session cookie which will expires when browser lost the session. I used the below code to read all the cookies in browser. But, i couldn''t get the cookie that i am looking for.

Request.ServerVariables["HTTP_COOKIE"];



请帮助我通过.NET应用程序读取Cookie值.

问候,
Vijay Kumar E,



Please help me in reading the cookie value through .NET application.

Regards,
Vijay Kumar E,

推荐答案

您可以使用以下函数获取Cookie值.

You can get the cookie value using following function.

getCookieValue("Cookie_key");

public static string getCookieValue(string strKey)
    {
        if (HttpContext.Current.Response.Cookies[strKey] != null && HttpContext.Current.Response.Cookies[strKey].Value + "" != "")
        {
            return HttpContext.Current.Response.Cookies[strKey].Value;
        }
        else if (HttpContext.Current.Request.Cookies[strKey] != null)
        {
            HttpContext.Current.Response.Cookies[strKey].Value = HttpContext.Current.Request.Cookies[strKey].Value;
            return HttpContext.Current.Request.Cookies[strKey].Value;
        }
        else
        {
            return "";
        }
    }


这篇关于在asp.net中读取Cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆