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 (471 )
1
+ # Samples for ASP.NET Core 6.0 (472 )
2
2
3
- Samples for ASP.NET Core ** 8.0 Preview 4** is available [ here] ( /projects/.net8 ) (9 ).
3
+ Samples for ASP.NET Core ** 8.0 Preview 4** is available [ here] ( /projects/.net8 ) (10 ).
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 (9 )
1
+ # ASP.NET 8.0 Preview 4 (10 )
2
2
3
3
These samples require [ .NET 8.0 Preview 4] ( https://github.com/dotnet/installer#table ) .
4
4
@@ -35,6 +35,10 @@ These samples require [.NET 8.0 Preview 4](https://github.com/dotnet/installer#t
35
35
36
36
This sample demonstrates how to configure a request timeout.
37
37
38
+ * [ Request Timeout Policy] ( request-timeout-2 )
39
+
40
+ Trigger exception on a timeout using ` HttpContext.RequestAborted.ThrowIfCancellationRequested() ` on a timeout that was specified using a named policy.
41
+
38
42
* [ Short Circuit] ( map-short-circuit )
39
43
40
44
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 . AddPolicy ( "quick" , 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 ( "quick" ) ;
32
+
33
+ app . Run ( ) ;
Original file line number Diff line number Diff line change
1
+ # Name timeout policy
2
+
3
+ Trigger exception on a timeout using ` HttpContext.RequestAborted.ThrowIfCancellationRequested() ` on a timeout that was specified using a named 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