All Products
Search
Document Center

Object Storage Service:Query endpoint information (C# SDK V2)

Last Updated:Aug 06, 2025

This topic describes how to use C# SDK V2 to query endpoint information for all supported regions or a specific region. This information includes Internet (IPv4) endpoints, internal endpoints for classic networks or VPCs, and acceleration endpoints for global upload and download acceleration.

Notes

  • You can query endpoint information for all regions that OSS supports, regardless of whether you have created a bucket in those regions.

  • The sample code in this topic uses the China (Hangzhou) region ID, cn-hangzhou, as an example. The Internet endpoint is used by default. If you want to access OSS from other Alibaba Cloud products in the same region, you must use the internal endpoint. For more information about the mappings between OSS regions and endpoints, see OSS regions and endpoints.

Query the endpoint information for all supported regions

The following code provides an example of how to query the endpoint information for all supported regions.

using OSS = AlibabaCloud.OSS.V2; // Create an alias for the Alibaba Cloud OSS SDK to simplify subsequent use.
using AlibabaCloud.OSS.V2.Models;

var region = "cn-hangzhou"; // Required. The region. In this example, the region is set to China (Hangzhou), which corresponds to the region ID cn-hangzhou.
var endpoint = null as string;  // Optional. The domain name used to access the OSS service. In this example, the endpoint for the China (Hangzhou) region is https://oss-cn-hangzhou.aliyuncs.com.

// Load the default configurations of the OSS SDK. The configurations automatically read credential information (such as AccessKeys) from environment variables.
var cfg = OSS.Configuration.LoadDefault();
// Explicitly set the use of environment variables to obtain credentials for identity verification (format: OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET).
cfg.CredentialsProvider = new OSS.Credentials.EnvironmentVariableCredentialsProvider();
// Set the region of the bucket in the configuration.
cfg.Region = region;
// If an endpoint is specified, overwrite the default endpoint.
if(endpoint != null)
{
    cfg.Endpoint = endpoint;
}

// Create an OSS client instance using the configuration information.
using var client = new OSS.Client(cfg);

// Create a request object.
var request = new DescribeRegionsRequest();

// Call the DescribeRegionsAsync method.
var result = await client.DescribeRegionsAsync(request);

Console.WriteLine("Alibaba Cloud OSS region information list:");
foreach (var regionInfo in result.RegionInfoList.RegionInfos)
{
    Console.WriteLine($"===== Region: {regionInfo.Region} =====");
            
    // Print the endpoint.
    Console.WriteLine($"  - Internet Endpoint: {regionInfo.InternetEndpoint}");
    Console.WriteLine($"  - Internal Endpoint: {regionInfo.InternalEndpoint}");
    Console.WriteLine($"  - Acceleration Endpoint: {regionInfo.AccelerateEndpoint}");
    Console.WriteLine("-------------------------");
}