.NET Core 3 with React - window.location.reload 401 error



这是一个 .net core 3 react 应用程序,如果用户关闭模态,我正在尝试重新加载当前页面。
下面是模式关闭处理程序:

handleClose = () => {
this.setState({ show: false });
window.location.reload(true); //I have also tried with default false
};

以下是浏览器中的详细信息:

General:    
Request URL: https://localhost:44378/Detail/ShowDetail
Request Method: GET
Status Code: 401 
Remote Address: [::1]:44378
Referrer Policy: no-referrer-when-downgrade
ResponseHeaders:
date: Thu, 30 Jan 2020 23:34:31 GMT
server: Microsoft-IIS/10.0
status: 401
www-authenticate: Bearer
x-powered-by: ASP.NET
Request Headers:
:authority: localhost:44378
:method: GET
:path: /Detail/ShowDetail
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
cookie: .AspNetCore.Antiforgery.wTfz....
pragma: no-cache
referer: https://localhost:44378/Detail/ShowDetail
sec-fetch-mode: navigate
sec-fetch-site: same-origin
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

以下是启动中的配置服务:

services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddRoleManager<RoleManager<IdentityRole>>()
.AddEntityFrameworkStores<ApplicationDbContext>();

services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.AddTransient<IProfileService, ProfileService>();
services.Configure<JwtBearerOptions>(
IdentityServerJwtConstants.IdentityServerJwtBearerScheme,
options =>
{                    
var onTokenValidated = options.Events.OnTokenValidated;
options.Events.OnTokenValidated = async context =>
{
await onTokenValidated(context);
};
});

为什么我可以毫无问题地导航到此页面,但重新加载会导致 401? CORS相关? 如果是这样,如何解决这个问题?

很可能你的 React 应用程序在https://localhost:4437提供,/Detail/ShowDetail是 React 应用程序中的一条路由。因此,通过请求https://localhost:44378/Detail/ShowDetail来攻击服务器是行不通的,因为服务器不知道/Detail/ShowDetail,只知道/(React(。

如果您愿意,您可以将所有请求路由到/在服务器端。我会推荐

不尝试重新加载,只是清除适当的状态属性

正如你所说。