この質問は、ここの質問/回答にかなり依存しています:
asp.net MVC4 アプリケーションで Servicestack セッションに再接続する
基本的に、認証に ServiceStack を使用する asp.net MVC アプリケーションがあります。上記の質問で示唆されているように、セッション Cookie を応答に追加し、後でそれを jsonserviceclient Cookie コンテナーに追加しています。
このコードを使用して、ログイン画面でユーザーを認証します。
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult login(UserModel user)
{
try
{
var AuthResponse = client.Post(new Auth
{
provider = "credentials",
UserName = user.user_id,
Password = user.password,
RememberMe = true
});
if (AuthResponse.SessionId != null)
{
FormsAuthentication.SetAuthCookie(AuthResponse.UserName, true);
var response = System.Web.HttpContext.Current.Response.ToResponse();
response.Cookies.AddSessionCookie(
SessionFeature.PermanentSessionId, AuthResponse.SessionId);
return Redirect("/Default");
}
}
catch (Exception ex)
{
FormsAuthentication.SignOut();
return Redirect("/");
}
return View();
}
ただし、次の行から null ref 例外が発生しています。
response.Cookies.AddSessionCookie(SessionFeature.PermanentSessionId, AuthResponse.SessionId);
スタック トレースは次のようになります。
at ServiceStack.ServiceHost.Cookies.ToHttpCookie(Cookie cookie)
at ServiceStack.ServiceHost.Cookies.AddCookie(Cookie cookie)
at ServiceStack.ServiceHost.Cookies.AddSessionCookie(String cookieName, String cookieValue, Nullable`1 secureOnly)
at FmStoreScreenMvc3.Controllers.AuthController.login(UserModel user) in <project> 51
この構成に明らかに問題があるように見えるかどうか疑問に思っています。
更新/メモ 問題のある行(nullrefがスローされる場所)を次のように変更しました:
response.Cookies.AddSessionCookie("foo", "bar", false);
それでも同じエラーが発生します。null とその理由を探しているだけです