Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

private async Task PostRequest()
{
var requestMessage = new HttpRequestMessage()
using var requestMessage = new HttpRequestMessage()
{
Method = new HttpMethod("POST"),
RequestUri = new Uri("https://localhost:10000/api/TodoItems"),
Expand All @@ -41,7 +41,7 @@
requestMessage.Content.Headers.TryAddWithoutValidation(
"x-custom-header", "value");

var response = await Http.SendAsync(requestMessage);
using var response = await Http.SendAsync(requestMessage);
var responseStatusCode = response.StatusCode;

responseBody = await response.Content.ReadAsStringAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
{
var client = ClientFactory.CreateClient();

var response =
using var response =
await client.PostAsync("https://localhost:5001/Filesave",
content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

private async Task PostRequest()
{
var requestMessage = new HttpRequestMessage()
using var requestMessage = new HttpRequestMessage()
{
Method = new HttpMethod("POST"),
RequestUri = new Uri("https://localhost:10000/api/TodoItems"),
Expand All @@ -41,7 +41,7 @@
requestMessage.Content.Headers.TryAddWithoutValidation(
"x-custom-header", "value");

var response = await Http.SendAsync(requestMessage);
using var response = await Http.SendAsync(requestMessage);
var responseStatusCode = response.StatusCode;

responseBody = await response.Content.ReadAsStringAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

if (upload)
{
var response = await Http.PostAsync("/Filesave", content);
using var response = await Http.PostAsync("/Filesave", content);

var newUploadResults = await response.Content
.ReadFromJsonAsync<IList<UploadResult>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
{
var client = ClientFactory.CreateClient();

var response =
using var response =
await client.PostAsync("https://localhost:5001/Filesave",
content);

Expand Down
2 changes: 1 addition & 1 deletion 6.0/BlazorSample_Server/Pages/images/ShowFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var absoluteUrl = NavigationManager.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

private async Task PostRequest()
{
var requestMessage = new HttpRequestMessage()
using var requestMessage = new HttpRequestMessage()
{
Method = new HttpMethod("POST"),
RequestUri = new Uri("https://localhost:10000/api/TodoItems"),
Expand All @@ -39,7 +39,7 @@
requestMessage.Content.Headers.TryAddWithoutValidation(
"x-custom-header", "value");

var response = await Http.SendAsync(requestMessage);
using var response = await Http.SendAsync(requestMessage);
var responseStatusCode = response.StatusCode;

responseBody = await response.Content.ReadAsStringAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

if (upload)
{
var response = await Http.PostAsync("/Filesave", content);
using var response = await Http.PostAsync("/Filesave", content);

var newUploadResults = await response.Content
.ReadFromJsonAsync<IList<UploadResult>>();
Expand Down
2 changes: 1 addition & 1 deletion 6.0/BlazorSample_WebAssembly/Pages/images/ShowFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var absoluteUrl = NavigationManager.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
{
var client = ClientFactory.CreateClient();

var response =
using var response =
await client.PostAsync("https://localhost:5001/Filesave",
content);

Expand Down
2 changes: 1 addition & 1 deletion 7.0/BlazorSample_Server/Pages/images/ShowFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var absoluteUrl = NavigationManager.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

private async Task PostRequest()
{
var requestMessage = new HttpRequestMessage()
using var requestMessage = new HttpRequestMessage()
{
Method = new HttpMethod("POST"),
RequestUri = new Uri("https://localhost:10000/api/TodoItems"),
Expand All @@ -39,7 +39,7 @@
requestMessage.Content.Headers.TryAddWithoutValidation(
"x-custom-header", "value");

var response = await Http.SendAsync(requestMessage);
using var response = await Http.SendAsync(requestMessage);
var responseStatusCode = response.StatusCode;

responseBody = await response.Content.ReadAsStringAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

if (upload)
{
var response = await Http.PostAsync("/Filesave", content);
using var response = await Http.PostAsync("/Filesave", content);

var newUploadResults = await response.Content
.ReadFromJsonAsync<IList<UploadResult>>();
Expand Down
2 changes: 1 addition & 1 deletion 7.0/BlazorSample_WebAssembly/Pages/images/ShowFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var absoluteUrl = NavigationManager.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
{
var client = ClientFactory.CreateClient();

var response =
using var response =
await client.PostAsync("https://localhost:5001/Filesave",
content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var absoluteUrl = Navigation.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
2 changes: 1 addition & 1 deletion 8.0/BlazorSample_WebAssembly/Pages/FileUpload2.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

if (upload)
{
var response = await Http.PostAsync("/Filesave", content);
using var response = await Http.PostAsync("/Filesave", content);

var newUploadResults = await response.Content
.ReadFromJsonAsync<IList<UploadResult>>();
Expand Down
2 changes: 1 addition & 1 deletion 8.0/BlazorSample_WebAssembly/Pages/ShowFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var absoluteUrl = Navigation.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ else

protected override async Task OnInitializedAsync()
{
var request = new HttpRequestMessage(HttpMethod.Get, "/weather-forecast");
using var request = new HttpRequestMessage(HttpMethod.Get, "/weather-forecast");
var client = ClientFactory.CreateClient("ExternalApi");
var response = await client.SendAsync(request);
using var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

forecasts = await response.Content.ReadFromJsonAsync<WeatherForecast[]>() ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{
var client = ClientFactory.CreateClient("Auth");

var response = await client.PostAsJsonAsync<FormModel>(endpoint, model);
using var response = await client.PostAsJsonAsync<FormModel>(endpoint, model);

if (response.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
try
{
// the user info endpoint is secured, so if the user isn't logged in this will fail
var userResponse = await httpClient.GetAsync("manage/info");
using var userResponse = await httpClient.GetAsync("manage/info");

// throw if user info wasn't retrieved
userResponse.EnsureSuccessStatusCode();
Expand All @@ -192,7 +192,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
.Select(c => new Claim(c.Key, c.Value)));

// request the roles endpoint for the user's roles
var rolesResponse = await httpClient.GetAsync("roles");
using var rolesResponse = await httpClient.GetAsync("roles");

// throw if request fails
rolesResponse.EnsureSuccessStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
{
var client = ClientFactory.CreateClient();

var response =
using var response =
await client.PostAsync("https://localhost:5001/Filesave",
content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var absoluteUrl = Navigation.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
2 changes: 1 addition & 1 deletion 9.0/BlazorSample_WebAssembly/Pages/FileUpload2.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

if (upload)
{
var response = await Http.PostAsync("/Filesave", content);
using var response = await Http.PostAsync("/Filesave", content);

var newUploadResults = await response.Content
.ReadFromJsonAsync<IList<UploadResult>>();
Expand Down
2 changes: 1 addition & 1 deletion 9.0/BlazorSample_WebAssembly/Pages/ShowFile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var absoluteUrl = Navigation.ToAbsoluteUri(url);
Console.WriteLine($"Downloading file from {absoluteUrl}");

var response = await Http.GetAsync(absoluteUrl);
using var response = await Http.GetAsync(absoluteUrl);
string? contentType = null;

if (response.Content.Headers.TryGetValues("Content-Type", out var values))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class ServerWeatherForecaster(IDownstreamApi downstreamApi) : IW
{
public async Task<IEnumerable<WeatherForecast>> GetWeatherForecastAsync()
{
var response = await downstreamApi.CallApiForUserAsync("DownstreamApi",
using var response = await downstreamApi.CallApiForUserAsync("DownstreamApi",
options =>
{
options.RelativePath = "/weather-forecast";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class ServerWeatherForecaster(IDownstreamApi downstreamApi) : IW
{
public async Task<IEnumerable<WeatherForecast>> GetWeatherForecastAsync()
{
var response = await downstreamApi.CallApiForUserAsync("DownstreamApi",
using var response = await downstreamApi.CallApiForUserAsync("DownstreamApi",
options =>
{
options.RelativePath = "/weather-forecast";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ else

protected override async Task OnInitializedAsync()
{
var request = new HttpRequestMessage(HttpMethod.Get, "/weather-forecast");
using var request = new HttpRequestMessage(HttpMethod.Get, "/weather-forecast");
var client = ClientFactory.CreateClient("ExternalApi");
var response = await client.SendAsync(request);
using var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

forecasts = await response.Content.ReadFromJsonAsync<WeatherForecast[]>() ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{
var client = ClientFactory.CreateClient("Auth");

var response = await client.PostAsJsonAsync<FormModel>(endpoint, model);
using var response = await client.PostAsJsonAsync<FormModel>(endpoint, model);

if (response.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
try
{
// the user info endpoint is secured, so if the user isn't logged in this will fail
var userResponse = await httpClient.GetAsync("manage/info");
using var userResponse = await httpClient.GetAsync("manage/info");

// throw if user info wasn't retrieved
userResponse.EnsureSuccessStatusCode();
Expand All @@ -192,7 +192,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
.Select(c => new Claim(c.Key, c.Value)));

// request the roles endpoint for the user's roles
var rolesResponse = await httpClient.GetAsync("roles");
using var rolesResponse = await httpClient.GetAsync("roles");

// throw if request fails
rolesResponse.EnsureSuccessStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private async Task<ClaimsPrincipal> LoginWithProviderAsync(LoginRequest loginMod
//Call the Login endpoint and pass the email and password
var httpClient = HttpClientHelper.GetHttpClient();
var loginData = new { loginModel.Email, loginModel.Password };
var response = await httpClient.PostAsJsonAsync(HttpClientHelper.LoginUrl, loginData);
using var response = await httpClient.PostAsJsonAsync(HttpClientHelper.LoginUrl, loginData);

LoginStatus = response.IsSuccessStatusCode ? LoginStatus.Success : LoginStatus.Failed;

Expand Down Expand Up @@ -168,7 +168,7 @@ private async Task<bool> RefreshAccessTokenAsync(string refreshToken, string ema
//Call the Refresh endpoint and pass the refresh token
var httpClient = HttpClientHelper.GetHttpClient();
var refreshData = new { refreshToken };
var response = await httpClient.PostAsJsonAsync(HttpClientHelper.RefreshUrl, refreshData);
using var response = await httpClient.PostAsJsonAsync(HttpClientHelper.RefreshUrl, refreshData);
response.EnsureSuccessStatusCode();
var token = await response.Content.ReadAsStringAsync();
_accessToken = await TokenStorage.SaveTokenToSecureStorageAsync(token, email);
Expand Down
4 changes: 2 additions & 2 deletions BlazorWebAssemblyXrefGenerator/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
{
var client = ClientFactory.CreateClient();
var encodedUrl = WebUtility.UrlEncode($"https://learn.microsoft.com/en-us{result.Url}?view={dotNetVersion}");
var request = new HttpRequestMessage(HttpMethod.Get, $"https://corsproxy.io/?{encodedUrl}");
var response = await client.SendAsync(request);
using var request = new HttpRequestMessage(HttpMethod.Get, $"https://corsproxy.io/?{encodedUrl}");
using var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();

var match = Regex.Match(content, "<meta name=\"ms.assetid\" content=\"(.+?)\" />");
Expand Down
Loading