File tree Expand file tree Collapse file tree 3 files changed +52
-2
lines changed Expand file tree Collapse file tree 3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ using System ;
11
+ using System . Runtime . Serialization ;
12
+ using React . Exceptions ;
13
+
14
+ namespace React . Web . Exceptions
15
+ {
16
+ [ Serializable ]
17
+ public class ReactAspNetException : ReactException
18
+ {
19
+ /// <summary>
20
+ /// Initializes a new instance of the <see cref="ReactAspNetException"/> class.
21
+ /// </summary>
22
+ /// <param name="message">The message that describes the error.</param>
23
+ public ReactAspNetException ( string message ) : base ( message ) { }
24
+
25
+ /// <summary>
26
+ /// Initializes a new instance of the <see cref="ReactAspNetException"/> class.
27
+ /// </summary>
28
+ /// <param name="message">The error message that explains the reason for the exception.</param>
29
+ /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
30
+ public ReactAspNetException ( string message , Exception innerException )
31
+ : base ( message , innerException ) { }
32
+
33
+ /// <summary>
34
+ /// Used by deserialization
35
+ /// </summary>
36
+ protected ReactAspNetException ( SerializationInfo info , StreamingContext context )
37
+ : base ( info , context ) { }
38
+ }
39
+ }
Original file line number Diff line number Diff line change 67
67
<Compile Include =" AspNetCache.cs" />
68
68
<Compile Include =" AspNetFileSystem.cs" />
69
69
<Compile Include =" AssemblyRegistration.cs" />
70
+ <Compile Include =" Exceptions\ReactAspNetException.cs" />
70
71
<Compile Include =" IJsxHandler.cs" />
71
72
<Compile Include =" TinyIoCAspNetExtensions.cs" />
72
73
<Compile Include =" WebInitializer.cs" />
Original file line number Diff line number Diff line change 11
11
using System . Linq ;
12
12
using System . Web ;
13
13
using React . TinyIoC ;
14
+ using React . Web . Exceptions ;
14
15
15
16
namespace React . Web . TinyIoC
16
17
{
@@ -35,7 +36,8 @@ public class HttpContextLifetimeProvider : TinyIoCContainer.ITinyIoCObjectLifeti
35
36
/// <returns>Object instance or null</returns>
36
37
public object GetObject ( )
37
38
{
38
- return HttpContext . Current . Items [ _keyName ] ;
39
+ var context = HttpContext . Current ;
40
+ return context == null ? null : context . Items [ _keyName ] ;
39
41
}
40
42
41
43
/// <summary>
@@ -44,7 +46,15 @@ public object GetObject()
44
46
/// <param name="value">Object to store</param>
45
47
public void SetObject ( object value )
46
48
{
47
- HttpContext . Current . Items [ _keyName ] = value ;
49
+ var context = HttpContext . Current ;
50
+ if ( context == null )
51
+ {
52
+ throw new ReactAspNetException (
53
+ "Trying to store item in HttpContext.Current while not in an ASP.NET " +
54
+ "request!"
55
+ ) ;
56
+ }
57
+ context . Items [ _keyName ] = value ;
48
58
}
49
59
50
60
/// <summary>
You can’t perform that action at this time.
0 commit comments