與我的許多ServiceStack問題一樣,我相信這會很容易。未設置AppHostBase實例
我有一個asp.net MCC4應用程序,我在其中使用ServiceStack進行身份驗證。因爲由ServiceStack客戶端生成的Cookie不共享,我一直遵循這樣的問題的答覆來解決問題:
ServiceStack Session always null in MVC Controller
在我的客戶我有這樣的代碼片段:
var authService = AppHostBase.Resolve<AuthService>();
authService.RequestContext = System.Web.HttpContext.Current.ToRequestContext();
var AuthResponse = authService.Authenticate(new Auth
{
provider = "credentials",
UserName = user.user_id,
Password = user.password,
RememberMe = true
});
if (AuthResponse.SessionId != null)
{
Session["IsAuthenticated"] = true;
Session["UserID"] = AuthResponse.UserName;
FormsAuthentication.SetAuthCookie(user.user_id, true);
return Redirect("/home");
}
else
{
Session["IsAuthenticated"] = false;
}
當我嘗試和運行應用程序,我得到的錯誤:「AppHostBase未初始化」
我可能會缺少什麼?我提前道歉,因爲我對ASP.net的一般經驗不足。
更新
我應該指出,這僅僅是將使用ServiceStack API這是一個不同的項目的一部分MCV4客戶端應用程序。
更新2
我認爲這可能是我的SS的不完美理解的一部分,它將如何融入Web應用程序,如這一點。我相信我真的可以理解的是,這個ASP.net客戶端如何通過ServiceStack API服務器上的現有會話進行備份。
什麼是你的控制器繼承一個cache provider?此外,這個片段有什麼方法? – mickfold
繼承自ControllerBase,片段來自「public ActionResult登錄(UserModel用戶)」 – SeanH