From f0974c550bf5a3db21fa3d7678447faac9589a9f Mon Sep 17 00:00:00 2001 From: Fiyaz Bin Hasan Date: Wed, 12 Oct 2022 19:13:21 +0600 Subject: [PATCH 1/3] work --- .../Controllers/Home2Controller.cs | 33 -- .../Controllers/HomeController.cs | 32 ++ .../Data/ApplicationDbContext.cs | 13 +- .../WebRateLimitAuth/Models/ErrorViewModel.cs | 13 +- .../Models/MyRateLimitOptions.cs | 19 +- .../Pages/Shared/_Layout.cshtml | 4 +- .../rate-limit/WebRateLimitAuth/Program.cs | 452 +++++++++--------- .../SampleRateLimiterPolicy.cs | 16 +- .../Views/{Home2 => Home}/Index.cshtml | 2 +- .../Views/{Home2 => Home}/Privacy.cshtml | 0 .../appsettings.Development.json | 18 +- .../WebRateLimitAuth/appsettings.json | 18 +- 12 files changed, 298 insertions(+), 322 deletions(-) delete mode 100644 fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/Home2Controller.cs create mode 100644 fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/HomeController.cs rename fundamentals/middleware/rate-limit/WebRateLimitAuth/Views/{Home2 => Home}/Index.cshtml (67%) rename fundamentals/middleware/rate-limit/WebRateLimitAuth/Views/{Home2 => Home}/Privacy.cshtml (100%) diff --git a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/Home2Controller.cs b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/Home2Controller.cs deleted file mode 100644 index d749e4d4..00000000 --- a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/Home2Controller.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using System.Diagnostics; -using WebRateLimitAuth.Models; - -namespace WebRateLimitAuth.Controllers -{ - public class Home2Controller : Controller - { - private readonly ILogger _logger; - - public Home2Controller(ILogger logger) - { - _logger = logger; - } - - public IActionResult Index() - { - return View(); - } - - public async Task Privacy() - { - await Task.Delay(100); - return View(); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - } -} diff --git a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/HomeController.cs b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/HomeController.cs new file mode 100644 index 00000000..5b0010dc --- /dev/null +++ b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Controllers/HomeController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using WebRateLimitAuth.Models; + +namespace WebRateLimitAuth.Controllers; + +public class HomeController : Controller +{ + private readonly ILogger _logger; + + public HomeController(ILogger logger) + { + _logger = logger; + } + + public IActionResult Index() + { + return View(); + } + + public async Task Privacy() + { + await Task.Delay(100); + return View(); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } +} diff --git a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Data/ApplicationDbContext.cs b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Data/ApplicationDbContext.cs index 5b16ab6c..a2af1e21 100644 --- a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Data/ApplicationDbContext.cs +++ b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Data/ApplicationDbContext.cs @@ -1,13 +1,12 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; -namespace WebRateLimitAuth.Data +namespace WebRateLimitAuth.Data; + +public class ApplicationDbContext : IdentityDbContext { - public class ApplicationDbContext : IdentityDbContext + public ApplicationDbContext(DbContextOptions options) + : base(options) { - public ApplicationDbContext(DbContextOptions options) - : base(options) - { - } } -} \ No newline at end of file +} diff --git a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/ErrorViewModel.cs b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/ErrorViewModel.cs index 3b1d0520..8f481af7 100644 --- a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/ErrorViewModel.cs +++ b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/ErrorViewModel.cs @@ -1,9 +1,8 @@ -namespace WebRateLimitAuth.Models +namespace WebRateLimitAuth.Models; + +public class ErrorViewModel { - public class ErrorViewModel - { - public string? RequestId { get; set; } + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } -} \ No newline at end of file + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); +} diff --git a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/MyRateLimitOptions.cs b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/MyRateLimitOptions.cs index 5d87e469..b173911d 100644 --- a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/MyRateLimitOptions.cs +++ b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Models/MyRateLimitOptions.cs @@ -3,14 +3,13 @@ namespace WebRateLimitAuth.Models; public class MyRateLimitOptions { public const string MyRateLimit = "MyRateLimit"; - - public int permitLimit { get; set; } = 100; - public int window { get; set; } = 10; - public int replenishmentPeriod { get; set; } = 2; - public int queueLimit { get; set; } = 100; - public int segmentsPerWindow { get; set; } = 8; - public int tokenLimit { get; set; } = 10; - public int tokenLimit2 { get; set; } = 20; - public int tokensPerPeriod { get; set; } = 4; - public bool autoReplenishment { get; set; } = false; + public int PermitLimit { get; set; } = 100; + public int Window { get; set; } = 10; + public int ReplenishmentPeriod { get; set; } = 2; + public int QueueLimit { get; set; } = 100; + public int SegmentsPerWindow { get; set; } = 8; + public int TokenLimit { get; set; } = 10; + public int TokenLimit2 { get; set; } = 20; + public int TokensPerPeriod { get; set; } = 4; + public bool AutoReplenishment { get; set; } = false; } diff --git a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Pages/Shared/_Layout.cshtml b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Pages/Shared/_Layout.cshtml index c476ede1..11e86e51 100644 --- a/fundamentals/middleware/rate-limit/WebRateLimitAuth/Pages/Shared/_Layout.cshtml +++ b/fundamentals/middleware/rate-limit/WebRateLimitAuth/Pages/Shared/_Layout.cshtml @@ -26,10 +26,10 @@ RP Privacy