是否可以从类扩展中访问会话变量?
我在会话中设置了这个变量:
var offset = 3;
HttpContext.Session.SetInt32("clienttimeoffset", offset);
在DateTime扩展中,我需要访问它:
public static DateTime? ToClientTime(this DateTime? value)
{
if (value == null)
return null;
var offset = get it here .....
....
}
答案 0 :(得分:0)
不要在扩展程序中访问它。将它作为参数传递给扩展方法:
public static DateTime? ToClientTime(this DateTime? value, int offset)
{
if (value == null)
return null;
....
}