CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.Web/ApplicationContextManager.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ApplicationContextManager.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Application context manager that uses HttpContext</summary>
7//-----------------------------------------------------------------------
8using Csla.Core;
9using System.Web;
10
11namespace Csla.Web
12{
18 {
23 { }
24
25 private const string _localContextName = "Csla.LocalContext";
26 private const string _clientContextName = "Csla.ClientContext";
27
33 public bool IsValid
34 {
35 get { return HttpContext.Current != null; }
36 }
37
42 public bool IsStatefulContext => false;
43
47 public System.Security.Principal.IPrincipal GetUser()
48 {
49 var result = HttpContext.Current.User;
50 if (result == null)
51 {
52 result = new System.Security.Claims.ClaimsPrincipal();
53 SetUser(result);
54 }
55 return result;
56 }
57
62 public void SetUser(System.Security.Principal.IPrincipal principal)
63 {
64 HttpContext.Current.User = principal;
65 }
66
71 {
72 return (ContextDictionary)HttpContext.Current.Items[_localContextName];
73 }
74
79 public void SetLocalContext(ContextDictionary localContext)
80 {
81 HttpContext.Current.Items[_localContextName] = localContext;
82 }
83
89 {
90 return (ContextDictionary)HttpContext.Current.Items[_clientContextName];
91 }
92
98 public void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
99 {
100 HttpContext.Current.Items[_clientContextName] = clientContext;
101 }
102
103 private const string _applicationContextName = "Csla.ApplicationContext";
104
109 {
110 get
111 {
112 return (ApplicationContext)HttpContext.Current.Items[_applicationContextName];
113 }
114 set
115 {
116 HttpContext.Current.Items[_applicationContextName] = value;
117 }
118 }
119 }
120}
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Application context manager that uses HttpContext to store context values.
void SetUser(System.Security.Principal.IPrincipal principal)
Sets the current principal.
System.Security.Principal.IPrincipal GetUser()
Gets the current principal.
void SetClientContext(ContextDictionary clientContext, ApplicationContext.ExecutionLocations executionLocation)
Sets the client context.
bool IsValid
Gets a value indicating whether this context manager is valid for use in the current environment.
bool IsStatefulContext
Gets a value indicating whether the current runtime is stateful (e.g.
void SetLocalContext(ContextDictionary localContext)
Sets the local context.
ApplicationContextManager()
Creates an instance of the type.
ContextDictionary GetLocalContext()
Gets the local context.
ContextDictionary GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
Gets the client context.
Defines the interface for an application context manager type.