HttpListenerRequest.UrlReferrer Proprietà

Definizione

Ottiene l'URI della risorsa che ha associato il client al server.

public:
 property Uri ^ UrlReferrer { Uri ^ get(); };
public Uri? UrlReferrer { get; }
public Uri UrlReferrer { get; }
member this.UrlReferrer : Uri
Public ReadOnly Property UrlReferrer As Uri

Valore della proprietà

Uri

Oggetto Uri contenente il testo dell'intestazione Referer della richiesta oppure null se l'intestazione non era inclusa nella richiesta.

Esempio

L'esempio di codice seguente illustra l'uso di questa proprietà.

public static void ShowRequestProperties1 (HttpListenerRequest request)
{
    // Display the MIME types that can be used in the response.
    string[] types = request.AcceptTypes;
    if (types != null)
    {
        Console.WriteLine("Acceptable MIME types:");
        foreach (string s in types)
        {
            Console.WriteLine(s);
        }
    }
    // Display the language preferences for the response.
    types = request.UserLanguages;
    if (types != null)
    {
        Console.WriteLine("Acceptable natural languages:");
        foreach (string l in types)
        {
            Console.WriteLine(l);
        }
    }

    // Display the URL used by the client.
    Console.WriteLine("URL: {0}", request.Url.OriginalString);
    Console.WriteLine("Raw URL: {0}", request.RawUrl);
    Console.WriteLine("Query: {0}", request.QueryString);

    // Display the referring URI.
    Console.WriteLine("Referred by: {0}", request.UrlReferrer);

    //Display the HTTP method.
    Console.WriteLine("HTTP Method: {0}", request.HttpMethod);
    //Display the host information specified by the client;
    Console.WriteLine("Host name: {0}", request.UserHostName);
    Console.WriteLine("Host address: {0}", request.UserHostAddress);
    Console.WriteLine("User agent: {0}", request.UserAgent);
}
Public Shared Sub ShowRequestProperties1(ByVal request As HttpListenerRequest)
    ' Display the MIME types that can be used in the response.
    Dim types As String() = request.AcceptTypes

    If types IsNot Nothing Then
        Console.WriteLine("Acceptable MIME types:")

        For Each s As String In types
            Console.WriteLine(s)
        Next
    End If

    ' Display the language preferences for the response.
    types = request.UserLanguages

    If types IsNot Nothing Then
        Console.WriteLine("Acceptable natural languages:")

        For Each l As String In types
            Console.WriteLine(l)
        Next
    End If

    ' Display the URL used by the client.
    Console.WriteLine("URL: {0}", request.Url.OriginalString)
    Console.WriteLine("Raw URL: {0}", request.RawUrl)
    Console.WriteLine("Query: {0}", request.QueryString)

    ' Display the referring URI.
    Console.WriteLine("Referred by: {0}", request.UrlReferrer)

    ' Display the HTTP method.
    Console.WriteLine("HTTP Method: {0}", request.HttpMethod)

    ' Display the host information specified by the client.
    Console.WriteLine("Host name: {0}", request.UserHostName)
    Console.WriteLine("Host address: {0}", request.UserHostAddress)
    Console.WriteLine("User agent: {0}", request.UserAgent)
End Sub

Commenti

Se un client ha seguito un collegamento ipertestuale all'URI richiesto, la relativa richiesta potrebbe contenere un'intestazione Referrer che identifica l'URI della risorsa che contiene il collegamento ipertestuale.

I client possono falsificare o scegliere di non presentare un'intestazione Referer . Pertanto, anche se la UrlReferrer proprietà può essere utile per identificare le tendenze di base nel traffico Web, non è consigliabile usarla come parte di uno schema di autorizzazione per controllare l'accesso ai dati.

Per un elenco completo di intestazioni di richiesta, vedere l'enumerazione HttpRequestHeader .

Il UrlReferrer valore è Null quando non Referrer è presente alcuna intestazione nella richiesta o quando l'intestazione Referrer è presente nella richiesta, ma non analizza in un oggetto valido Uri.

Si applica a

Vedi anche