File tree Expand file tree Collapse file tree 5 files changed +51
-3
lines changed Expand file tree Collapse file tree 5 files changed +51
-3
lines changed Original file line number Diff line number Diff line change 1
- # Samples for ASP.NET Core 6.0 (472 )
1
+ # Samples for ASP.NET Core 6.0 (473 )
2
2
3
- Samples for ASP.NET Core ** 8.0 Preview 4** is available [ here] ( /projects/.net8 ) (10 ).
3
+ Samples for ASP.NET Core ** 8.0 Preview 4** is available [ here] ( /projects/.net8 ) (11 ).
4
4
5
5
Samples for ASP.NET Core ** 7.0** is available [ here] ( /projects/.net7 ) (45).
6
6
Original file line number Diff line number Diff line change 1
- # ASP.NET 8.0 Preview 4 (10 )
1
+ # ASP.NET 8.0 Preview 4 (11 )
2
2
3
3
These samples require [ .NET 8.0 Preview 4] ( https://github.com/dotnet/installer#table ) .
4
4
@@ -39,6 +39,10 @@ These samples require [.NET 8.0 Preview 4](https://github.com/dotnet/installer#t
39
39
40
40
Trigger exception on a timeout using ` HttpContext.RequestAborted.ThrowIfCancellationRequested() ` on a timeout that was specified using a named policy.
41
41
42
+ * [ Request Timeout Policy] ( request-timeout-3 )
43
+
44
+ Trigger exception on a timeout using ` HttpContext.RequestAborted.ThrowIfCancellationRequested() ` on a default timeout policy.
45
+
42
46
* [ Short Circuit] ( map-short-circuit )
43
47
44
48
Use ` MapShortCircuit ` or ` .ShortCircuit() ` to efficiently respond to a request without going through a middleware pipeline run.
Original file line number Diff line number Diff line change
1
+ var builder = WebApplication . CreateBuilder ( ) ;
2
+ builder . Services . AddRequestTimeouts ( options =>
3
+ {
4
+ options . DefaultPolicy = new Microsoft . AspNetCore . Http . Timeouts . RequestTimeoutPolicy
5
+ {
6
+ Timeout = TimeSpan . FromSeconds ( 1 ) ,
7
+ TimeoutStatusCode = 200 ,
8
+ WriteTimeoutResponse = async ( HttpContext context ) =>
9
+ {
10
+ context . Response . ContentType = "text/plain" ;
11
+ await context . Response . WriteAsync ( "timeout is triggered" ) ;
12
+ }
13
+ } ;
14
+ } ) ;
15
+
16
+ var app = builder . Build ( ) ;
17
+ app . UseRequestTimeouts ( ) ;
18
+
19
+ app . MapGet ( "/" , async ( HttpContext context ) => {
20
+ await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
21
+
22
+ context . RequestAborted . ThrowIfCancellationRequested ( ) ;
23
+
24
+ return Results . Content ( """
25
+ <html>
26
+ <body>
27
+ hello world
28
+ </body>
29
+ </html>
30
+ """ , "text/html" ) ;
31
+ } ) . WithRequestTimeout ( policy : null ) ;
32
+
33
+ app . Run ( ) ;
Original file line number Diff line number Diff line change
1
+ # Default timeout policy
2
+
3
+ Trigger exception on a timeout using ` HttpContext.RequestAborted.ThrowIfCancellationRequested() ` on a default timeout policy.
Original file line number Diff line number Diff line change
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 >
You can’t perform that action at this time.
0 commit comments