Tracking down error occurring with "Request" object

Discussion in 'ASP .Net' started by Ben Amada, Aug 17, 2004.

  1. Ben Amada

    Ben Amada Guest

    Hello! There are a couple of visitors (out of dozens) to this web page who
    are causing the following error to occur:

    "Object reference not set to an instance of an object."

    I'm actually catching this error in a Try-Catch block. I've narrowed down
    the possible offending code to the 3 lines below:

    Request.Browser.Cookies
    Request.UserAgent.ToString
    Request.UserHostAddress.ToString

    Is it possible for any of the 3 lines of code above to generate the error
    listed above? For instance, is is possible that "Browser", "UserAgent" or
    "UserHostAddress" would not be automatically instantiated in some cases?

    Any help or ideas are appreciated!
    Ben
     
    Ben Amada, Aug 17, 2004
    #1
    1. Advertising

  2. Ben,

    It's probably the string casts. You can't cast Nothing to a string and the
    UserAgent and / or UserHostAddress may not contain any info.

    I would check if they are instantiated before the string cast with an if
    then like this:

    If Not Request.UserAgent Is Nothing Then
    Dim UserAgent As String = Request.UserAgent.ToString
    End If

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Ben Amada" <> wrote in message
    news:ujdm%23c$...
    > Hello! There are a couple of visitors (out of dozens) to this web page
    > who
    > are causing the following error to occur:
    >
    > "Object reference not set to an instance of an object."
    >
    > I'm actually catching this error in a Try-Catch block. I've narrowed down
    > the possible offending code to the 3 lines below:
    >
    > Request.Browser.Cookies
    > Request.UserAgent.ToString
    > Request.UserHostAddress.ToString
    >
    > Is it possible for any of the 3 lines of code above to generate the error
    > listed above? For instance, is is possible that "Browser", "UserAgent" or
    > "UserHostAddress" would not be automatically instantiated in some cases?
    >
    > Any help or ideas are appreciated!
    > Ben
    >
    >
     
    S. Justin Gengo, Aug 17, 2004
    #2
    1. Advertising

  3. Ben Amada

    Ben Amada Guest

    S. Justin Gengo wrote:

    > It's probably the string casts. You can't cast Nothing to a string and the
    > UserAgent and / or UserHostAddress may not contain any info.
    >
    > I would check if they are instantiated before the string cast with an if
    > then like this:
    >
    > If Not Request.UserAgent Is Nothing Then
    > Dim UserAgent As String = Request.UserAgent.ToString
    > End If


    Thanks for the reply! Testing to see if UserAgent / UserHostAddress is
    Nothing or not seems like a good solution -- I'll make that change right
    away. I'm curious as to what browser, security settings and/or conditions
    lead to UserAgent or UserHostAddress not containing any data. I thought
    they always contain data. Hmm...

    Ben
     
    Ben Amada, Aug 17, 2004
    #3
  4. Ben,

    I'm not certain which settings / services cause it either. It is really just
    the way that the header is sent out. Almost any program or service could be
    modifying them. Norton Personal Firewall, AOL, are likely culprits. :)

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Ben Amada" <> wrote in message
    news:...
    > S. Justin Gengo wrote:
    >
    >> It's probably the string casts. You can't cast Nothing to a string and
    >> the
    >> UserAgent and / or UserHostAddress may not contain any info.
    >>
    >> I would check if they are instantiated before the string cast with an if
    >> then like this:
    >>
    >> If Not Request.UserAgent Is Nothing Then
    >> Dim UserAgent As String = Request.UserAgent.ToString
    >> End If

    >
    > Thanks for the reply! Testing to see if UserAgent / UserHostAddress is
    > Nothing or not seems like a good solution -- I'll make that change right
    > away. I'm curious as to what browser, security settings and/or conditions
    > lead to UserAgent or UserHostAddress not containing any data. I thought
    > they always contain data. Hmm...
    >
    > Ben
    >
    >
     
    S. Justin Gengo, Aug 17, 2004
    #4
  5. Ben Amada

    Ben Amada Guest

    S. Justin Gengo wrote:

    > Ben,
    >
    > I'm not certain which settings / services cause it either. It is really
    > just the way that the header is sent out. Almost any program or service
    > could be modifying them. Norton Personal Firewall, AOL, are likely
    > culprits. :)


    I'm actually logging to a DB the user's UserAgent and UserHostAddress.
    After making the change you suggested, I no longer get errors and I just
    discovered by looking at the DB that for this particular user, it's his
    UserAgent data which is empty. Also Request.Browser.Cookies is returning a
    False value for this user which means that his browser doesn't even support
    cookies which I've never seen before. Usually the return value for Cookies
    will be True -- whether they have configured their browser to accept cookies
    or not is another issue.

    Thanks,
    Ben
     
    Ben Amada, Aug 18, 2004
    #5
    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. DesignerX
    Replies:
    2
    Views:
    464
    DesignerX
    Jul 30, 2003
  2. Replies:
    10
    Views:
    434
    Gabriel Genellina
    Feb 8, 2008
  3. Philip

    ValidationSummary - PostBack still occurring

    Philip, Aug 3, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    291
    Philip
    Aug 3, 2008
  4. C3
    Replies:
    8
    Views:
    138
  5. Replies:
    0
    Views:
    93
Loading...

Share This Page