我想使用会话功能但没有认证。我已经添加Plugins.Add(new SessionFeature())
到AppHost.cs
并且我有以下代码
public class CustomService : Service
{
public CustomResponse Any(CustomRequest pRequest)
{
var CustomSession = base.Session.Get<CustomType>("MySession");//try to get the session
if (CustomSession == null)
{
//create a new session
CustomSession = new CustomType{MyId=1};
base.Session["MySession"] = CustomSession;
//base.Session.Set("MySession", CustomSession); //also tried this, to save the session.
this.SaveSession(CustomSession, new TimeSpan (0,20,0)); //Save the Session
}
}
}
我遇到的问题base.Session.Get<CustomType>("MySession")
是总是null
. 我在会话的实施中遗漏了什么吗?