WebRequestExtensions.GetCurrentNetworkInterface Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets all available information about the network interface that corresponds to a web request.

Namespace: Microsoft.Phone.Net.NetworkInformation
Assembly: Microsoft.Phone (in Microsoft.Phone.dll)


<ExtensionAttribute> _
Public Shared Function GetCurrentNetworkInterface ( _
    request As WebRequest _
) As NetworkInterfaceInfo
public static NetworkInterfaceInfo GetCurrentNetworkInterface(
    this WebRequest request


Return Value

Type: Microsoft.Phone.Net.NetworkInformation..::.NetworkInterfaceInfo
All available information about the network interface. Use the InterfaceType and InterfaceSubtype properties to determine the network interface technology.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type WebRequest. When you use instance method syntax to call this method, omit the first parameter.


This method must be invoked from the UI thread.

For more information about extension methods, see Extension Methods (C# Programming Guide) or How to: Call an Extension Method (Visual Basic).


The following example shows how to call the GetCurrentNetworkInterface method from the UI thread. The call to GetCurrentNetworkInterface throws a NetworkException if the web request has already completed.

private void response_Callback(IAsyncResult asyncResult)
            HttpWebRequest httpWebRequest = (HttpWebRequest)asyncResult.AsyncState;
            Dispatcher.BeginInvoke(() =>
                    NetworkInterfaceInfo networkInterfaceInfo = httpWebRequest.GetCurrentNetworkInterface();
                catch (NetworkException networkException)
                    if (networkException.NetworkErrorCode == NetworkError.WebRequestAlreadyFinished)
                        System.Diagnostics.Debug.WriteLine("Cannot call GetCurrentNetworkInterface if the webrequest is already complete");


Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1


Windows Phone

See Also


WebRequestExtensions Class

Microsoft.Phone.Net.NetworkInformation Namespace