Skip to content

Commit 3274b37

Browse files
committed
Add RequestTimeout sample
1 parent d37c5d2 commit 3274b37

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Http.Timeouts;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
var builder = WebApplication.CreateBuilder();
5+
builder.Services.AddControllers();
6+
7+
var app = builder.Build();
8+
app.UseRequestTimeouts();
9+
app.MapControllers();
10+
11+
app.Run();
12+
13+
public class HomeController : ControllerBase
14+
{
15+
[HttpGet("/")]
16+
[RequestTimeout(milliseconds: 1)]
17+
public async Task<IActionResult> Index()
18+
{
19+
await Task.Delay(100);
20+
HttpContext.RequestAborted.ThrowIfCancellationRequested();
21+
return Ok("Hello World!");
22+
}
23+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Use RequestTimeout attribute
2+
3+
Use `RequestTimeout` attribute to specify how many milliseconds a time out will be trigerred.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ImplicitUsings>true</ImplicitUsings>
5+
<LangVersion>preview</LangVersion>
6+
<PreviewFeatures>true</PreviewFeatures>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "request-timeout-4", "request-timeout-4.csproj", "{82B2E0B5-E009-4F7C-AEDA-AB3DD2A50101}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{82B2E0B5-E009-4F7C-AEDA-AB3DD2A50101}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{82B2E0B5-E009-4F7C-AEDA-AB3DD2A50101}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{82B2E0B5-E009-4F7C-AEDA-AB3DD2A50101}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{82B2E0B5-E009-4F7C-AEDA-AB3DD2A50101}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7FD5CF14-91DD-4569-AD32-DE58589AC66C}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)