Skip to content

Commit 3dd3b52

Browse files
Merge pull request #35099 from dotnet/main
Merge to Live
2 parents 2982e58 + 65d2bbd commit 3dd3b52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+86266
-49
lines changed

aspnetcore/performance/rate-limit-samples.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ uid: performance/rate-limit-sample
1313

1414
The following samples aren't production quality, they're examples on how to use the limiters.
1515

16-
### Limiter with `OnRejected`, `RetryAfter`, and `GlobalLimiter`
16+
## Limiter with `OnRejected`, `RetryAfter`, and `GlobalLimiter`
1717

1818
The following sample:
1919

@@ -41,13 +41,13 @@ The `SampleRateLimiterPolicy` class
4141

4242
In the preceding code, <xref:Microsoft.AspNetCore.RateLimiting.RateLimiterOptions.OnRejected> uses <xref:Microsoft.AspNetCore.RateLimiting.OnRejectedContext> to set the response status to [429 Too Many Requests](https://developer.mozilla.org/docs/Web/HTTP/Status/429). The default rejected status is [503 Service Unavailable](https://developer.mozilla.org/docs/Web/HTTP/Status/503).
4343

44-
### Limiter with authorization
44+
## Limiter with authorization
4545

4646
The following sample uses JSON Web Tokens (JWT) and creates a partition with the JWT [access token](https://github.com/dotnet/aspnetcore/blob/fd1891536f27e959d14a140ff9307b6a21191de9/src/Security/Authentication/JwtBearer/src/JwtBearerHandler.cs#L152-L158). In a production app, the JWT would typically be provided by a server acting as a Security token service (STS). For local development, the dotnet [user-jwts](xref:security/authentication/jwt) command line tool can be used to create and manage app-specific local JWTs.
4747

4848
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/middleware/rate-limit/WebRateLimitAuth/Program.cs" id="snippet_jwt":::
4949

50-
### Limiter with `ConcurrencyLimiter`, `TokenBucketRateLimiter`, and authorization
50+
## Limiter with `ConcurrencyLimiter`, `TokenBucketRateLimiter`, and authorization
5151

5252
The following sample:
5353

@@ -57,4 +57,5 @@ The following sample:
5757

5858
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/middleware/rate-limit/WebRateLimitAuth/Program.cs" id="snippet_adm2":::
5959

60-
See [the samples repository for the complete `Program.cs`](https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/middleware/rate-limit/WebRateLimitAuth/Program.cs#L145,L281) file.
60+
See [the samples repository for the complete `Program.cs`](https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/middleware/rate-limit/WebRateLimitAuth/Program.cs#L145,L281) file.
61+

aspnetcore/performance/rate-limit.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,7 @@ Implementing a commercial DDoS protection service in conjunction with rate limit
5252

5353
The following steps show how to use the rate limiting middleware in an ASP.NET Core app:
5454

55-
1. Install the `Microsoft.AspNetCore.RateLimiting` package.:
56-
57-
Add the `Microsoft.AspNetCore.RateLimiting` package to the project, via the NuGet Package Manager or the following command:
58-
59-
```sh
60-
dotnet add package Microsoft.AspNetCore.RateLimiting
61-
```
62-
63-
2. Configure rate limiting services.
55+
1. Configure rate limiting services.
6456

6557
In the `Program.cs` file, configure the rate limiting services by adding the appropriate rate limiting policies. Policies can either be defined as global or named polices. The following example permits 10 requests per minute by user (identity) or globally:
6658

@@ -101,7 +93,7 @@ The following steps show how to use the rate limiting middleware in an ASP.NET C
10193

10294
The global limiter applies to all endpoints automatically when it's configured via [options.GlobalLimiter](/dotnet/api/microsoft.aspnetcore.ratelimiting.ratelimiteroptions.globallimiter).
10395

104-
3. Enable rate limiting middleware
96+
2. Enable rate limiting middleware
10597

10698
In the `Program.cs` file, enable the rate limiting middleware by calling [UseRateLimiter](/dotnet/api/microsoft.aspnetcore.builder.ratelimiterapplicationbuilderextensions.useratelimiter):
10799

aspnetcore/signalr/diagnostics.md

Lines changed: 81 additions & 35 deletions
Large diffs are not rendered by default.
103 KB
Loading
98.6 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.AspNetCore.SignalR;
2+
3+
namespace SignalRChat.Hubs
4+
{
5+
public class ChatHub : Hub
6+
{
7+
public async Task SendMessage(string user, string message)
8+
{
9+
await Clients.All.SendAsync("ReceiveMessage", user, message);
10+
}
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace SignalRChat.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@page
2+
<div class="container">
3+
<div class="row p-1">
4+
<div class="col-1">User</div>
5+
<div class="col-5"><input type="text" id="userInput" /></div>
6+
</div>
7+
<div class="row p-1">
8+
<div class="col-1">Message</div>
9+
<div class="col-5"><input type="text" class="w-100" id="messageInput" /></div>
10+
</div>
11+
<div class="row p-1">
12+
<div class="col-6 text-end">
13+
<input type="button" id="sendButton" value="Send Message" />
14+
</div>
15+
</div>
16+
<div class="row p-1">
17+
<div class="col-6">
18+
<hr />
19+
</div>
20+
</div>
21+
<div class="row p-1">
22+
<div class="col-6">
23+
<ul id="messagesList"></ul>
24+
</div>
25+
</div>
26+
</div>
27+
<script src="~/js/signalr/dist/browser/signalr.js"></script>
28+
<script src="~/js/chat.js"></script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace SignalRChat.Pages
5+
{
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)