model view controller - Get value from cookie mvc -


i set value cookie in 1 mvc controler this

        httpcookie accesstoken = new httpcookie("accesstoken");         accesstoken.values["accesstoken"] = "cb7ca44ff81324186724867668572a8f";         response.setcookie(accesstoken); 

when value cookie in controler this

httpcontext.request.cookies.get("accesstoken"); 

or this

request.cookies["accesstoken"].value 

i

accesstoken=cb7ca44ff81324186724867668572a8f

i want value without key, doing wrong?

you adding key-value pair accesstoken cookie. if storing 1 value , don't need dictionary structure, can use httpcookie.value property.

accesstoken.value = "cb7ca44ff81324186724867668572a8f"; request.cookies["accesstoken"].value // output 'cb7ca44ff81324186724867668572a8f' 

update: if want store multiple key-value pairs did initially, then:

var accesstoken = new httpcookie("accesstoken"); accesstoken["somekey1"] = somevalue1; accesstoken["somekey2"] = somevalue2;  // read values string somevalue1 = request.cookies["accesstoken"]["somekey1"]; string somevalue2 = request.cookies["accesstoken"]["somekey2"]; 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -