I've added app.UseSession();
to my startup.Configure and services.AddSession()
to my ConfigureServices.
Now if I try to use Session like this:
HttpContext.Session.SetString("Type", tableName);
I get "an object reference is required for the non-static field, method or property, 'HttpContext.Session'"
However, if I try to instantiate it like this:
HttpContext context = new HttpContext();
it says: "Cannot create an instance of the abstract class or interface 'HttpContext"
How can I access session?
IQuery.cs
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace AppName.Services
{
public interface IQuery
{
List<Dictionary<string, string>> GetListOfDatabases(string dbName);
}
public class InMemoryIquery : IQuery
{
public List<Dictionary<string, string>> GetListOfDatabases(string tableName)
{
if(tableName != null)
{
HttpContext.Session.SetString("Type", tableName);
}
}
}