首页 > 解决方案 > 在 ASP.Net Core 中将不记名令牌添加到 ajax POST 请求

问题描述

我有一个用ASP.Net Core 中的属性/Home/PostRequest装饰的 POST 方法。[Authorize]客户端我有一个经过身份验证的用户。我想构造一个 ajax POST 请求来调用该方法,但我不确定将什么放入 Authorization 标头中。身份验证凭据缓存在哪里,以什么形式缓存?

$.ajax({
            type: "POST",
            url: "/Home/PostRequest",
            data: JSON.stringify(request),
            headers: {
                "Authorization": "** what to put here? **"
            }
            contentType: "application/json",
            dataType: "json",
            crossDomain: false,
            success: function (response) {
                successCallback(response);
            },
            failure: function (response) {
                console.log("Failed");
            },
            error: function (xhr, response, thrownError) {
                console.log("Error");
            }
        });

标签: ajaxasp.net-core

解决方案


推荐阅读