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.
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|