如何令牌存储在MVC的cookie并将其发送到API [英] How to store token in mvc cookie and send it to api

查看:106
本文介绍了如何令牌存储在MVC的cookie并将其发送到API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送凭据到API,它通过MVC登录方法创建一个用户,然后我在网页API创建令牌和响应MVC返回令牌现在我想保存令牌MVC中的Cookie,并再次创下API总监授权时发送的Web API采取行动。

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.

请给我建议这两个东西

推荐答案

有没有一个整体很多​​在这里工作,但总的来讲,网络API从MVC发散大多是在它的充分休息兼容,而MVC是没有的。符合REST的应用程序是无状态的(换句话说:无会话,没有饼干等)。一切API终端需求必须与请求一起发送无论是在URL中,请求头或请求主体。这意味着你可以发的的一个GET请求或POST身体的查询字符串中的cookie(而不是饼干,本身),或者作为典型的REST API身份验证,作为授权 HTTP标头。

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.

这篇关于如何令牌存储在MVC的cookie并将其发送到API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆