开发者

Difference Between Request.Cookies["UserID"] and Request.Cookies["UserID"].Value

开发者 https://www.devze.com 2023-01-19 19:39 出处:网络
here is my sample code. i m checking the code for null user ID, still it is getting executed....! if (!IsPostBack == true && Request.Cookies[\"UserID\"] != null)

here is my sample code. i m checking the code for null user ID, still it is getting executed....!

    if (!IsPostBack == true && Request.Cookies["UserID"] != null)
    {
        string userID = Request.Co开发者_运维百科okies["UserID"].Value;
        myPageBL.GetFriendRequests(userID); // this can never be null, but is taking null
    }


Request.Cookies["UserID"] != null should tell you whether the Cookie with name "UserID" exists whereas Request.Cookies["UserID"].Value tells you the actual Value named as "UserID" inside the cookie.


Request.Cookies["UserID"]

Will return a HttpCookie object called "UserID", or null if it doesn't exist.

Request.Cookies["UserID"].Value 

Will return the Value of the HttpCookie.

So, what could be happening is that the Cookie is there, but the value is empty.

But still, i can't see how the Value could be null. string.Emtpy maybe, but not null.

0

精彩评论

暂无评论...
验证码 换一张
取 消