This repository was archived by the owner on Nov 20, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Microsoft.AspNet.Http.Abstractions Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) .NET Foundation. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+ namespace Microsoft . AspNet . Http
5+ {
6+ public interface IHttpContextAccessor
7+ {
8+ HttpContext HttpContext { get ; set ; }
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) .NET Foundation. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+ using System ;
5+ #if DNX451
6+ using System . Runtime . Remoting . Messaging ;
7+ using System . Runtime . Remoting ;
8+ #elif DNXCORE50
9+ using System . Threading ;
10+ #endif
11+
12+ namespace Microsoft . AspNet . Http . Internal
13+ {
14+ public class HttpContextAccessor : IHttpContextAccessor
15+ {
16+ #if DNX451
17+ private const string LogicalDataKey = "__HttpContext_Current__" ;
18+
19+ public HttpContext HttpContext
20+ {
21+ get
22+ {
23+ var handle = CallContext . LogicalGetData ( LogicalDataKey ) as ObjectHandle ;
24+ return handle != null ? handle . Unwrap ( ) as HttpContext : null ;
25+ }
26+ set
27+ {
28+ CallContext . LogicalSetData ( LogicalDataKey , new ObjectHandle ( value ) ) ;
29+ }
30+ }
31+
32+ #elif DNXCORE50
33+ private AsyncLocal < HttpContext > _httpContextCurrent = new AsyncLocal < HttpContext > ( ) ;
34+ public HttpContext HttpContext
35+ {
36+ get
37+ {
38+ return _httpContextCurrent . Value ;
39+ }
40+ set
41+ {
42+ _httpContextCurrent . Value = value ;
43+ }
44+ }
45+ #endif
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments