在服务器端的HttpContext.Current.Request.Cookies中找不到从react设置Cookie

时间:2018-08-21 02:30:13

标签: c# reactjs cookies model-view-controller redux-saga

我尝试在saga.js函数中使用:

import Cookies from 'universal-cookie';

export function* certLoginFlow() {
  while (true) {
...
var expiresDate = new Date();
expiresDate.setTime(expiresDate.getTime() + 24 * 60 * 60 * 1000 * 90); //90 day
 yield call(certificateLogin, { data });
...
}
}

//设置cookie:

const cookies = new Cookies();
cookies.set('CryptoProVersion', version, { path: '/', expires: expiresDate });

//尝试进入Web-api控制器:

  public static string ExtractCryptoInfo(HttpRequestBase request)
        {
            var Cookies = request.Cookies;

            if (Cookies != null && Cookies["CryptoProVersion"] != null)
            {
                return Cookies["CryptoProVersion"].Value;
            }
            return null;
        }

ExtractCryptoInfo始终返回null。为什么?我在做什么错了?

好吧,我认为一定是这样,但仍然无法正常工作

export function postRequest(url, data, cookies) {
  return fetch(url,
    {
      method: 'POST',
      credentials: 'same-origin',
      headers: {
        'Content-Type': 'application/json',
        'Set-Cookie': cookies
      },
      body: JSON.stringify(data)
    })
    .then(checkStatus)
    .then(parseJSON);
}

我也使用CORS。

0 个答案:

没有答案