开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜