Advertisement
Beginner .NET MAUI, Networking & APIs

How do you check network connectivity before making a request?

Short answer

Query Connectivity.Current.NetworkAccess (Internet, Local, None) and optionally ConnectionProfiles (WiFi, Cellular). Subscribe to ConnectivityChanged to react to changes. Use it to skip requests, show offline UI, or defer syncing on metered connections.

Save .NET MAUI mock interview
Advertisement
AModel answer
Query Connectivity.Current.NetworkAccess (Internet, Local, None) and optionally ConnectionProfiles (WiFi, Cellular). Subscribe to ConnectivityChanged to react to changes. Use it to skip requests, show offline UI, or defer syncing on metered connections.
if (Connectivity.Current.NetworkAccess != NetworkAccess.Internet)
{
    await DisplayAlert("Offline", "Check your connection.", "OK");
    return;
}
Real-world example
Before syncing large data, an app warns the user and waits when only cellular or no connection is available.
Likely follow-ups
  • What is ConnectivityChanged? | How do you detect metered connections?
Related topics