2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Diagnostics . CodeAnalysis ;
5
- using System . Text . Json ;
6
- using System . Text . Json . Serialization ;
7
5
using Microsoft . AspNetCore . Components . Web ;
8
6
9
7
namespace Microsoft . AspNetCore . Components . Forms ;
@@ -26,19 +24,11 @@ public DefaultAntiforgeryStateProvider(PersistentComponentState state)
26
24
// don't have access to the request.
27
25
_subscription = state . RegisterOnPersisting ( ( ) =>
28
26
{
29
- var bytes = JsonSerializer . SerializeToUtf8Bytes (
30
- GetAntiforgeryToken ( ) ,
31
- DefaultAntiforgeryStateProviderJsonSerializerContext . Default . AntiforgeryRequestToken ) ;
32
- state . PersistAsJson ( PersistenceKey , bytes ) ;
27
+ state . PersistAsJson ( PersistenceKey , GetAntiforgeryToken ( ) ) ;
33
28
return Task . CompletedTask ;
34
29
} , RenderMode . InteractiveAuto ) ;
35
30
36
- if ( state . TryTakeFromJson < byte [ ] > ( PersistenceKey , out var bytes ) )
37
- {
38
- _currentToken = JsonSerializer . Deserialize (
39
- bytes ,
40
- DefaultAntiforgeryStateProviderJsonSerializerContext . Default . AntiforgeryRequestToken ) ;
41
- }
31
+ state . TryTakeFromJson ( PersistenceKey , out _currentToken ) ;
42
32
}
43
33
44
34
/// <inheritdoc />
@@ -47,6 +37,3 @@ public DefaultAntiforgeryStateProvider(PersistentComponentState state)
47
37
/// <inheritdoc />
48
38
public void Dispose ( ) => _subscription . Dispose ( ) ;
49
39
}
50
-
51
- [ JsonSerializable ( typeof ( AntiforgeryRequestToken ) ) ]
52
- internal sealed partial class DefaultAntiforgeryStateProviderJsonSerializerContext : JsonSerializerContext ;
0 commit comments