How to store token in mvc cookie and send it to ap

2019-08-12 16:08发布

问题:

I am sending credentials to API which creates user then through MVC Login method i create token in Web API and return token in response to MVC now I want to store Token in MVC Cookie and again send it Web API when hitting API Controller authorized action.

Please suggest me these two things

回答1:

There's not a whole lot to work with here, but generally speaking, Web API diverges from MVC mostly in that it's fully REST-compliant, whereas MVC is not. REST-compliant applications are stateless (in other words: no session, no cookies, etc.). Everything the API endpoint needs must be sent along with the request either in the URL, the request headers or the request body. That means you could send the value of the cookie (not the cookie, itself) in the query string of a GET request or the body of a POST, or as is typical with REST API auth, as an Authorization HTTP header.