Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Get Session from Javascript in Core 2.0

$
0
0

Hi,

I have an extension method for sessions from MS docs

using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;

public static class SessionExtensions
{
    public static void Set<T>(this ISession session, string key, T value)
    {
        session.SetString(key, JsonConvert.SerializeObject(value));
    }

    public static T Get<T>(this ISession session,string key)
    {
        var value = session.GetString(key);
        return value == null ? default(T) :
                              JsonConvert.DeserializeObject<T>(value);
    }
}

I'm using that to store values in a class.

It's all good getting the values from controller, but is it possible to read the session from Javascript?

I read this but it's not for Core 2.0

I use this to get data from controller:

var Partner = HttpContext.Session.Get<PartnerData>("Partner");


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>