?
Solved

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

Posted on 2008-11-15
5
Medium Priority
?
1,673 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:jumpstart0321
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22967505
There is no guarantee that you will have a valid value in UrlReferrer. If you are using HTTPS protocol you will find it null.
0
 

Author Comment

by:jumpstart0321
ID: 22973372
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.
0
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 2000 total points
ID: 22986006
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
0
 

Author Comment

by:jumpstart0321
ID: 22987012
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
0
 

Author Closing Comment

by:jumpstart0321
ID: 31517087
Thanks man, much appreciated.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question