c# - nullreference exception when adding session cookie to ServiceStack -


this question relies quite bit on question/answer here:

reconnecting servicestack session in asp.net mvc4 application

basically, have asp.net mvc application using servicestack authentication. suggested in question mentioned above adding session cookie response , adding jsonserviceclient cookie container later.

using code authenticate user @ login screen:

    [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();     } 

however, getting null ref exception line:

response.cookies.addsessioncookie(sessionfeature.permanentsessionid, authresponse.sessionid); 

the stack trace looks like:

at servicestack.servicehost.cookies.tohttpcookie(cookie cookie) @ servicestack.servicehost.cookies.addcookie(cookie cookie) @ servicestack.servicehost.cookies.addsessioncookie(string cookiename, string cookievalue, nullable`1 secureonly) @ fmstorescreenmvc3.controllers.authcontroller.login(usermodel user) in <project> 51 

i'm wondering if seems wrong configuration.

update/note have changed offending line (where nullref thrown) to:

response.cookies.addsessioncookie("foo", "bar", false);  

i still same error. hunting null , why

instead of:

response.cookies.addsessioncookie(   sessionfeature.permanentsessionid, authresponse.sessionid); 

try:

response.setcookie(sessionfeature.permanentsessionid,      authresponse.sessionid, timespan.fromdays(14))); 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -