A
A
artshelom2019-02-21 20:21:53
ASP.NET
artshelom, 2019-02-21 20:21:53

Trying to add a session to a project?

I'm trying to add a line to the session:
HttpContext.Session.SetString("Train", "wewew");
In ConfigureServices I added:

services.AddDistributedMemoryCache();
services.AddSession();

In Configure added:
app.UseAuthentication();
app.UseSession();
      app.UseMvc(routes =>
      {
        routes.MapRoute(
          name: "default",
          template: "{controller=Home}/{action=Index}/{id?}");
      });

And it gives an error:
An unhandled exception occurred while processing the request.
InvalidOperationException: Session has not been configured for this application or request.
Microsoft.AspNetCore.Http.DefaultHttpContext.get_Session()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bashinsky, 2019-02-21
@artshelom

In configure add
app.UseSession();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question