File tree 3 files changed +20
-10
lines changed
3 files changed +20
-10
lines changed Original file line number Diff line number Diff line change 1
1
using asp_net_core_filters . Filters ;
2
2
using asp_net_core_filters . Models ;
3
- using Microsoft . AspNetCore . Authorization ;
4
3
using Microsoft . AspNetCore . Http ;
5
4
using Microsoft . AspNetCore . Mvc ;
5
+ using Microsoft . Extensions . Caching . Memory ;
6
6
using Microsoft . Extensions . Logging ;
7
7
using System ;
8
- using System . Collections . Generic ;
9
8
using System . Diagnostics ;
10
- using System . Linq ;
11
- using System . Security . Claims ;
12
- using System . Threading . Tasks ;
9
+ using System . Runtime . CompilerServices ;
13
10
14
11
namespace asp_net_core_filters . Controllers
15
12
{
16
13
public class HomeController : Controller
17
14
{
18
15
private readonly ILogger < HomeController > _logger ;
19
-
16
+ private readonly IMemoryCache _memoryCache ;
17
+
20
18
public HomeController ( ILogger < HomeController > logger )
21
19
{
22
20
_logger = logger ;
@@ -28,7 +26,13 @@ public IActionResult Index()
28
26
return View ( ) ;
29
27
}
30
28
31
- public IActionResult Privacy ( )
29
+ [ CacheResourceFilter ]
30
+ public IActionResult Message ( )
31
+ {
32
+ return Content ( "This content was generated at " + DateTime . Now ) ;
33
+ }
34
+
35
+ public IActionResult Privacy ( )
32
36
{
33
37
return View ( ) ;
34
38
}
Original file line number Diff line number Diff line change 1
1
using Microsoft . AspNetCore . Mvc ;
2
2
using Microsoft . AspNetCore . Mvc . Filters ;
3
+ using System ;
3
4
using System . Collections . Generic ;
4
5
5
6
namespace asp_net_core_filters . Filters
6
7
{
7
- public class CacheResourceFilter : IResourceFilter
8
+ public class CacheResourceFilter : Attribute , IResourceFilter
8
9
{
10
+ public CacheResourceFilter ( )
11
+ {
12
+
13
+ }
14
+
9
15
private static readonly Dictionary < string , object > _cache
10
16
= new Dictionary < string , object > ( ) ;
11
17
private string _cacheKey ;
Original file line number Diff line number Diff line change @@ -29,10 +29,10 @@ public void ConfigureServices(IServiceCollection services)
29
29
services . AddScoped < AuthorizeIPAddress > ( container =>
30
30
{
31
31
//test for valid authorization
32
- // return new AuthorizeIPAddress("127.0.0.1;192.168.1.5;::1");
32
+ return new AuthorizeIPAddress ( "127.0.0.1;192.168.1.5;::1" ) ;
33
33
34
34
//test for invalid authorization
35
- return new AuthorizeIPAddress ( "000.0.0.0" ) ;
35
+ // return new AuthorizeIPAddress("000.0.0.0");
36
36
} ) ;
37
37
}
38
38
You can’t perform that action at this time.
0 commit comments