Reactjs Asp.net core 2.0 react.js cookie身份验证同构获取循环
我有一个带有react.js的小型asp.net核心应用程序,它使用cookie身份验证对用户进行身份验证。 当我直接调用控制器的操作时,cookie身份验证似乎可以正常工作 例如,如果我键入,它将按预期工作。进行身份验证并创建cookie,在后一个请求中使用cookie 但是,当我的react组件使用同构fetch调用控制器方法时 它变成了无止境的身份验证循环Reactjs Asp.net core 2.0 react.js cookie身份验证同构获取循环,reactjs,asp.net-core,isomorphic-fetch-api,Reactjs,Asp.net Core,Isomorphic Fetch Api,我有一个带有react.js的小型asp.net核心应用程序,它使用cookie身份验证对用户进行身份验证。 当我直接调用控制器的操作时,cookie身份验证似乎可以正常工作 例如,如果我键入,它将按预期工作。进行身份验证并创建cookie,在后一个请求中使用cookie 但是,当我的react组件使用同构fetch调用控制器方法时 它变成了无止境的身份验证循环 [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.Aut
[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
public class TestController : Controller
{
public IActionResult Index()
{
return View();
}
}
这是我的startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOptions();
services.AddAuthentication(o =>
{
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultAuthenticateScheme =
CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(19);
options.AccessDeniedPath = "/Account/Forbidden/";
options.LoginPath = "/Account/Login/";
});
这里是我验证用户身份的地方。(AccountController/登录)
下面是我的fetch方法,它创建了无止境的登录循环
export class ProposalGrid extends React.Component<RouteComponentProps<{}>, FetchDataExampleState> {
constructor(props: RouteComponentProps<{}>) {
super(props);
this.pageChange = this.pageChange.bind(this);
this.state = { proposalDatas: [], loading: true, dataState: { take: 10, skip: 0 } };
let url = "ProposalData/GetProposals?" + $.param({ take: 10, skip: 0 })
fetch(url)
.then(response => response.json() as Promise<ProposalData[]>)
.then(data => {
this.setState({ proposalDatas: data, loading: false });
});
}
导出类ProposalGrid扩展React.Component{
构造函数(道具:RouteComponentProps){
超级(道具);
this.pageChange=this.pageChange.bind(this);
this.state={proposalDatas:[],loading:true,dataState:{take:10,skip:0};
let url=“ProposalData/GetPropositions?”+$.param({take:10,skip:0})
获取(url)
.then(response=>response.json()作为承诺)
。然后(数据=>{
this.setState({proposalDatas:data,loading:false});
});
}
我在获取数据并将方法更改为post时包含了凭据。问题消失了
fetch(url, {
method: 'POST',
credentials: 'include',
fetch(url, {
method: 'POST',
credentials: 'include',