ASP.net Request.UrlReferrer.Authority returning a object not set to reference of an object.

Here is the code:
                Dim sPreviousURL = Request.UrlReferrer.Authority
                If Not sPreviousURL = "" Then
                    Dim oSQLInsertDelete As SqlConnection = New SqlConnection("Connection")
                    Dim commandInsert As New SqlCommand("INSERT INTO Clean (InvalidCampaigns, Referrer) VALUES ('" & Request.QueryString("user") & "', '" & sPreviousURL & "')", oSQLInsertDelete)
                    oSQLInsertDelete.Open()
                    commandInsert.ExecuteReader()
                    oSQLInsertDelete.Close()
                End If
The statement "Request.UrlReferrer.Authority" is returning the error message. I've tried to research it all over the internet and all the solutions have gone unsolved. I could really use some help. Thanks, Chris.
jumpstart0321Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Toms EdisonTechnical ManagerCommented:
There is no guarantee that you will have a valid value in UrlReferrer. If you are using HTTPS protocol you will find it null.
jumpstart0321Author Commented:
Shouldn't this be handled by my statement:
If Not sPreviousURL = "" Then
<Process data>
If that doesn't work, can you suggest what I should use?Thanks.
Toms EdisonTechnical ManagerCommented:
When Request.UrlReferrer is null Request.UrlReferrer.Authority will throw an exception

You can check if Request.UrlReferrer is Nothing before accessing Authority

if Not Request.UrlReferrer is Nothing then
sPreviousURL = Request.UrlReferrer.Authority

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jumpstart0321Author Commented:
Got it. for public reference purposes, here is the code I used:
            Try
                If Not String.IsNullOrEmpty(Request.UrlReferrer.Authority) Then
                    'Response.Write(Request.UrlReferrer.Authority)
                    If Not Request.UrlReferrer.Authority.Contains("webspider") Then
                        Dim oSQLInsertDelete As SqlConnection = New SqlConnection("Connection")
                        Dim commandInsert As New SqlCommand("INSERT INTO Referrer (Referrer) VALUES ('" & Request.UrlReferrer.Authority & "')", oSQLInsertDelete)
                        oSQLInsertDelete.Open()
                        commandInsert.ExecuteReader()
                        oSQLInsertDelete.Close()
                    End If
                End If
            Catch ex As Exception
            End Try
jumpstart0321Author Commented:
Thanks man, much appreciated.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.