Possible unintended reference comparison

Discussion in 'ASP .Net' started by sotec, Dec 30, 2005.

  1. sotec

    sotec Guest

    erroe message and code portion is like this....
    how can i change this code to not occur to error

    if (page.Session["UserId"] == null || page.Session["UserId"] !=
    userId )
    {
    UserStatusSetting(page, userId);
    }

    Warning 2 Possible unintended reference comparison; to get a value
    comparison, cast the left hand side to type 'string'
    c:\inetpub\wwwroot\Minks\App_Code\SessionManager\SiteSessionManager.cs 28 51
    http://localhost/Minks/
     
    sotec, Dec 30, 2005
    #1
    1. Advertising

  2. Sotec,
    When you refer to an object that is stored in Session State, it doesn't
    ^automatically^ assume its initial type from when you stored it there. So
    for example, (if your userId is a string) you could use
    (string)page.Session["UserId"] and now you would be comparing a string to a
    string.
    Hope that helps.
    Peter
    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "sotec" wrote:

    >
    >
    > erroe message and code portion is like this....
    > how can i change this code to not occur to error
    >
    > if (page.Session["UserId"] == null || page.Session["UserId"] !=
    > userId )
    > {
    > UserStatusSetting(page, userId);
    > }
    >
    > Warning 2 Possible unintended reference comparison; to get a value
    > comparison, cast the left hand side to type 'string'
    > c:\inetpub\wwwroot\Minks\App_Code\SessionManager\SiteSessionManager.cs 28 51
    > http://localhost/Minks/
    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Dec 30, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kay Schluehr

    Unintended inheritance

    Kay Schluehr, Feb 20, 2006, in forum: Python
    Replies:
    2
    Views:
    454
    Kay Schluehr
    Feb 24, 2006
  2. Andreas Griesmayer

    GCC-Bug ? (Unintended "overloading")

    Andreas Griesmayer, Jul 31, 2006, in forum: C Programming
    Replies:
    20
    Views:
    591
    Ike Naar
    Aug 2, 2006
  3. Michael Sparks

    Nested Scopes unintended behaviour ?

    Michael Sparks, Mar 17, 2010, in forum: Python
    Replies:
    4
    Views:
    281
    Terry Reedy
    Mar 18, 2010
  4. Martin DeMello

    unintended consequence: string.sort

    Martin DeMello, Jul 5, 2007, in forum: Ruby
    Replies:
    2
    Views:
    102
    Martin DeMello
    Jul 5, 2007
  5. Replies:
    2
    Views:
    196
    smallpond
    Apr 29, 2009
Loading...

Share This Page