在ASP.NET Core Web应用程序中,如果无法找到cookie值,可能有以下几个原因:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.Name = "YourCookieName";
// 其他选项设置
});
app.UseRouting();
// 其他中间件
app.UseAuthentication();
// 其他中间件
app.UseEndpoints(endpoints =>
{
// 终结点配置
});
HttpContext.Response.Cookies.Append("YourCookieName", "YourCookieValue");
var cookieValue = HttpContext.Request.Cookies.Get("YourCookieName");
options.Cookie.Expires = DateTimeOffset.UtcNow.AddMinutes(30);
请根据你的具体情况检查以上可能的原因,并确保正确设置和读取Cookie值。如果问题仍然存在,可能需要进一步调试和排查。