刷新身份验证 cookie 导致找不到 .NET Core 路由器

问题描述 投票:0回答:1

我们正在构建一个 API,它将 GET 请求发送到我们的 .NET Core 应用程序以检索网页。为了符合身份验证,我们还为其提供 .NET 应用程序 cookie(仅在用户登录后从浏览器复制)。当 cookie 更改时(在这种情况下,当另一个用户请求 API 并发送他们自己的 cookie 时)就会出现问题。

身份验证正常通过(不返回登录页面),但 Router 组件似乎无法找到端点(落入路由器的 NotFound 部分)。有趣的是,如果我在 30-60 分钟后尝试使用同一个饼干,它会突然开始起作用。这让我认为这与使 cookie 无效/验证新的 cookie 有关。有谁知道问题可能是什么?

路由器代码:

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        </Found>
        <NotFound> //this is where it falls after the cookie changes
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

检查请求,用户声明的 cookie 是正确的,并且请求中存在正确的主机和路径...

.net cookies blazor asp.net-identity blazor-server-side
1个回答
0
投票

1.检查会话超时设置:确保会话超时时间不会太长,导致应用程序仍然使用旧的cookie。您可以在Startup.cs文件中的ConfigureServices方法中调整会话超时。

2.调查cookie验证逻辑:检查应用程序中是否存在任何可能导致新cookie无效或无法识别的自定义逻辑。这可能位于 ConfigureServices 方法或 Startup.cs 文件中。

3.检查缓存:确保没有缓存机制可能导致应用程序仍然使用旧的 cookie。您可以在Startup.cs文件中的ConfigureServices方法中检查这一点。

4.检查AuthenticationStateProvider:CascadingAuthenticationState组件依赖AuthenticationStateProvider来确定当前用户的身份验证状态。确保发送新 cookie 时正确配置和更新 AuthenticationStateProvider。

5.检查AuthorizeRouteView组件:确保AuthorizeRouteView组件配置正确并且能够识别新的cookie。您可以在 Router 组件的 Found 部分中检查这一点。

6.调查 AuthenticationState 类:确保 AuthenticationState 类已正确实现并且它能够识别新的 cookie。您可以在 Startup.cs 文件中检查这一点。

7.检查身份验证中间件:确保身份验证中间件配置正确并且能够识别新的 cookie。您可以在Startup.cs文件中的Configure方法中检查这一点。

© www.soinside.com 2019 - 2024. All rights reserved.