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!
VBBRettAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ZhaolaiConnect With a Mentor Commented:
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:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.