You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using Microsoft.AspNetCore.Http ;
using Newtonsoft.Json ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace Admin.Core.Common
{
/// <summary>
/// Isession的扩展, 存储复杂对象
/// </summary>
public static class SessionExtensions
{
public static void Set ( this ISession session , string key , object 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 ) ;
}
}
}