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 6767 <Compile Include =" AspNetCache.cs" />
6868 <Compile Include =" AspNetFileSystem.cs" />
6969 <Compile Include =" AssemblyRegistration.cs" />
70+ <Compile Include =" Exceptions\ReactAspNetException.cs" />
7071 <Compile Include =" IJsxHandler.cs" />
7172 <Compile Include =" TinyIoCAspNetExtensions.cs" />
7273 <Compile Include =" WebInitializer.cs" />
Original file line number Diff line number Diff line change 1111using System . Linq ;
1212using System . Web ;
1313using React . TinyIoC ;
14+ using React . Web . Exceptions ;
1415
1516namespace React . Web . TinyIoC
1617{
@@ -35,7 +36,8 @@ public class HttpContextLifetimeProvider : TinyIoCContainer.ITinyIoCObjectLifeti
3536 /// <returns>Object instance or null</returns>
3637 public object GetObject ( )
3738 {
38- return HttpContext . Current . Items [ _keyName ] ;
39+ var context = HttpContext . Current ;
40+ return context == null ? null : context . Items [ _keyName ] ;
3941 }
4042
4143 /// <summary>
@@ -44,7 +46,15 @@ public object GetObject()
4446 /// <param name="value">Object to store</param>
4547 public void SetObject ( object value )
4648 {
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 ;
4858 }
4959
5060 /// <summary>
You can’t perform that action at this time.
0 commit comments