1
我想使用會話功能但沒有進行身份驗證。 我已經加入到Plugins.Add(new SessionFeature())
和AppHost.cs
我有以下代碼未保存在ServiceStack中的會話
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
。 我在執行會話時丟失了什麼?
我試過,但我得到這個錯誤:ServiceStack.ServiceInterface.Service'不包含'SaveSession'的定義謝謝 – user2170206 2013-03-14 17:15:12
您使用ReSharper嗎?我用一些解決方法更新了我的答案。 – paaschpa 2013-03-14 17:32:03
是的,我使用ReSharper,你的工作似乎部分工作,但是當我運行代碼時,調用SaveSession時出現錯誤,它說:{「值不能爲null。\ r \ nParameter name:source」}。另外,對於「sess」,我不能使用自定義類型或字符串,而是使用AuthUserSession。 – user2170206 2013-03-14 18:32:05