示例#1
0
        /// <summary>
        /// Gets a value by key from context converted to the type specified by "T", or the default value for the type if not present.
        /// </summary>
        /// <typeparam name="T">The data type to which the value should be converted.</typeparam>
        /// <param name="key">The key associated with the value to return.</param>
        /// <returns>The value from context if present; otherwise the default value for the type.</returns>
        public T GetValue <T>(string key)
        {
            if (HttpContext.Current != null)
            {
                if (!HttpContext.Current.Items.Contains(key))
                {
                    return(default(T));
                }

                return((T)HttpContext.Current.Items[key]);
            }

            // No HttpContext
            if (_next != null)
            {
                return(_next.GetValue <T>(key));
            }

            // No HttpContext, no secondary context - throw a meaningful exception
            throw new NullReferenceException(
                      "HttpContext.Current is null and no secondary IContextStorage was provided (required in situations where context needs to be passed from HttpContext to worker threads in an ASP.NET application).");
        }
示例#2
0
 /// <summary>
 /// Gets the <see cref="SnapshotContext" /> for the current API request.
 /// </summary>
 /// <returns>The current context.</returns>
 public SnapshotContext GetSnapshotContext()
 {
     return(_contextStorage.GetValue <SnapshotContext>(SnapshotContextKeyName));
 }
 /// <inheritdoc cref="IAuthorizationFilterContextProvider.GetFilterContext" />
 public IReadOnlyList <AuthorizationStrategyFiltering> GetFilterContext()
 {
     return(_contextStorage.GetValue <IReadOnlyList <AuthorizationStrategyFiltering> >(FilterContextKeyName)
            ?? Array.Empty <AuthorizationStrategyFiltering>());
 }
 /// <summary>
 /// Gets parameterized filters from the current context, or an empty dictionary if none have been set.
 /// </summary>
 /// <returns>A dictionary keyed by filter name, whose values are dictionaries keyed by parameter name.</returns>
 public IReadOnlyList <AuthorizationFilterDetails> GetFilterContext()
 {
     return(_contextStorage.GetValue <IReadOnlyList <AuthorizationFilterDetails> >(FilterContextKeyName)
            ?? new AuthorizationFilterDetails[0]);
 }
示例#5
0
 public string GetInstanceId()
 {
     return(contextStorage.GetValue <string>(InstanceIdContextKey));
 }
示例#6
0
 public int GetSchoolYear()
 {
     return(contextStorage.GetValue <int>(SchoolYearContextKey));
 }
 public ApiKeyContext GetApiKeyContext()
 {
     return(_contextStorage.GetValue <ApiKeyContext>(ApiKeyContextKeyName)
            ?? ApiKeyContext.Empty);
 }
示例#8
0
 public string[] GetResourceUris()
 {
     return(_contextStorage.GetValue <string[]>(AuthorizationContextKeys.Resource));
 }