C# .net core RedirectToAction将丢失对当前用户的更改

C# .net core RedirectToAction将丢失对当前用户的更改,c#,security,.net-core,user-management,C#,Security,.net Core,User Management,我必须在home controller的索引操作中作为查询字符串来管理用户非音频化 在这种情况下,我更改了当前用户,它最终不能被允许访问索引视图,必须重定向到不同的视图 但是重定向的页面不能保留新用户(如果我打开标准视图,一切正常) 控制器动作 public IActionResult Index(string HTTP_USER_LOGIN = null) { if (HTTP_USER_LOGIN is not null) {

我必须在home controller的索引操作中作为查询字符串来管理用户非音频化

在这种情况下,我更改了当前用户,它最终不能被允许访问索引视图,必须重定向到不同的视图

但是重定向的页面不能保留新用户(如果我打开标准视图,一切正常)

控制器动作

public IActionResult Index(string HTTP_USER_LOGIN = null)
    {
        if (HTTP_USER_LOGIN is not null)
        {
            myUserManagement.SetUtenteImpersonato(HttpContext, HTTP_USER_LOGIN);
            return RedirectToAction("IndexVuota");
        }       
        return View();
    }
    public IActionResult IndexVuota()
    {
        return View();
    }
用户管理

public async Task<HttpContext> SetUtenteImpersonato(HttpContext context, string matricolaTarget)
    {

        ClaimsPrincipal principal = new ClaimsPrincipal(context.User.Identity);
        var identity = (ClaimsIdentity)principal.Identity;
        identity.AddClaim(new Claim(TipoClaim.nomeImpersonato.ToString(), "NEWUSER"));
        context.User = principal;
        return context;
    }
public异步任务setUteneImpersonato(HttpContext上下文,字符串矩阵目标)
{
ClaimsPrincipal principal=newclaimsprincipal(context.User.Identity);
var identity=(ClaimsIdentity)principal.identity;
identity.AddClaim(新声明(TipoClaim.nomeImpersonato.ToString(),“NEWUSER”);
context.User=principal;
返回上下文;
}

在IndexVuota
上下文中
没有“新用户”声明

您从服务器获得了一个cookie,cookie将返回到原始用户。但是为什么返回视图();在重定向到操作(“IndexVuota”)时使用修改后的cookie;没有?我只是想解释发生了什么。当使用IP时,会自动发送cookie。如果您正在更改用户,则需要不同的cookie(或不需要cookie)。当您调用
RedirectToAction
时,您是在告诉浏览器调用新的操作,这会在
IndexVuota
操作中为您提供一个全新的
HttpContext
操作。是否可以将当前
HttpContext
发送到
IndexVuota
操作?