Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

What am I doing wrong in my VB.net code?

I am trying to get where the referral url came from where a visitor would have came from.  So here is my code for my function:

 
Public Function Referralurl() As String

        Dim referringurl As String

        referringurl = Request.UrlReferrer.AbsolutePath

        If referringurl = Nothing Then
             referringurl = "Nothing"
        End If

        Return referringurl
    End Function

Open in new window


Immediately after I start my program, I get the error code: "Object Instance not set to an instance of an object on the line where it states the following:

Object reference not set to an instance of an object.

What can I do to fix this problem?  Thank you!
0
VBBRett
Asked:
VBBRett
  • 4
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
Since I am from mobile, I cannot read the code-snipplets fully. Could you please post the code as comment instead of as an attachment ?

Also specify which line is crashing.
Raj
0
 
Rajkumar GsSoftware EngineerCommented:
Normally this error message triggers when an object is not instantiated.

Raj
0
 
VBBRettAuthor Commented:
Yes, here is the code:

Public Function Referralurl() As String

        Dim referringurl As String

        referringurl = Request.UrlReferrer.AbsolutePath

        If referringurl = Nothing Then
             referringurl = "Nothing"
        End If

        Return referringurl
    End Function
 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ZhaolaiCommented:
Try this:

    Public Function Referralurl() As String

        Dim referringurl As String = String.Empty
        If Request.UrlReferrer IsNot Nothing Then
            referringurl = Request.UrlReferrer.AbsolutePath
        End If

        Return referringurl
    End Function

Open in new window

0
 
Rajkumar GsSoftware EngineerCommented:
Is this line is crashing ?
referringurl = Request.UrlReferrer.AbsolutePath

Raj
0
 
Rajkumar GsSoftware EngineerCommented:
Zhaolai has posted what is in my mind first.

...= String.Empty

Raj
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now