Skip to main content

ELL Blog

C# How to Uri Encode Strings and Queries

Use System.Uri.EscapeDateString

// using System;
var email = "email@gmail.com";
var url = $"/send-email?email={Uri.EscapeDataString(email)}";

In an ASP.NET Integration test:

[Fact]
public async Task TestPayouts() {
    var client = _factory.CreateClient();
    var url = $"/test/inc-payout?email={Uri.EscapeDataString(Constants.PAYOUT_TEST_ACCOUNT)}";
    var response = await client.PostAsync(url, null);

    response.EnsureSuccessStatusCode();
}