1

I have a REST API application made with .NET Core 2.0. I would like to access the Application property to store some global settings for all the application.

However, it doesn't seem to be available in any of my controllers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EcommerceSynchronizer.Controllers
{
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        // GET api/values
        [HttpGet]
        public string Get()
        {
            HttpContext.Current.Application["key"] = "value";
            return "aa";
        }
    }
}

Resharper complains that

'HttpContext' does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument ...

I tried accessing with HttpContext.Application but it is not available either.

How can I access HttpApplicationState from a controller ?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Arthur Attout
  • 2,701
  • 2
  • 26
  • 49
  • Poor design and no longer available in asp.net core, check docs for suggested approach https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-2.1&tabs=aspnetcore2x – Nkosi Apr 16 '18 at 11:49
  • Thanks, I had no idea this was removed. I will use Application State Data instead – Arthur Attout Apr 16 '18 at 11:57

0 Answers0