asp.net - Why my cookie is not visible from Global.asax? -


i'm going crazy please me.

i'm doing mvc application using asp.net 4.0 razor render, in application need build authentication system. have accontcontroller.cs file have following method:

 public actionresult login(loginmodel model, string returnurl)     {          var privatetoken = sessionhelper.gettoken();         var user = _application.login(privatetoken, model.username, model.password).results;          if (modelstate.isvalid && !user.isnull())         {             var serializemodel = new customprincipalserializedmodel                                      {                                          userid = user.username,                                          firstname = user.name,                                          token = privatetoken,                                          email = user.email                                      };              var serializer = new javascriptserializer();              string userdata = serializer.serialize(serializemodel);              var authticket = new formsauthenticationticket(              1,              user.username,              datetime.now,              datetime.now.adddays(1),              false,              userdata);              string encticket = formsauthentication.encrypt(authticket);              var cookie = new httpcookie("login", encticket);              request.cookies.add(cookie);               return redirecttolocal(returnurl);         }          // if got far, failed, redisplay form         modelstate.addmodelerror("", "the user name or password provided incorrect.");         return view(model);     } 

at point have created cookie.

into global.asax have following override:

protected void application_postauthenticaterequest(object sender, eventargs e)     {          httpcookie authcookie = request.cookies["login"];              if (authcookie.isnull() || authcookie.value.isnullorwhitespaces()) return;         ... here other stuff      } 

i need cookie return default cookie without value, why?

if try display view accountcontroller obtain correct cookie, instead if go in controller (for example homecontroller) obtain blank cookie.

o_o why?

update:

i have resolved in way:

   if (authticket.ispersistent)             {                 cookie.expires = authticket.expiration;             } 

but if want remove cookie with:

system.web.httpcontext.current.response.cookies.remove("login"); 

it doesn't works... -_- so... did this:

    [validateantiforgerytoken]     public actionresult logoff()     {         system.web.httpcontext.current.response.cookies["login"].expires = datetime.utcnow.adddays(-1);         //response.cookies.remove("login");         return redirecttoaction("index", "home");     } 

well... guys idiot or asp.net sucks? tnx help.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -