RedirectFromLoginPage()未更新User.Identity.Name [英] RedirectFromLoginPage() is not updating User.Identity.Name

查看:89
本文介绍了RedirectFromLoginPage()未更新User.Identity.Name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FormsAuthentication.RedirectFromLoginPage(userName.Trim(), false);设置我稍后引用的User.Identity.Name字段.当我执行这一行时,User.Identity对象根本不会更新;它包含以前设置的内容.我在网上看到的所有文档都说这应该用正确的名称更新User.Identity对象,但我看不到这种情况.

I use FormsAuthentication.RedirectFromLoginPage(userName.Trim(), false); to set the User.Identity.Name field that I reference later. When I execute this line, the User.Identity object does not update at all; it contains whatever it was previously set to. All the documentation I see online says this should update my User.Identity object with the correct name, but I don't see that happening.

我通过以下几行正确设置了Web配置:

I have the web config set up properly with the following lines:

<authentication mode="Forms">
    <forms name="formsauth" loginUrl="Login.aspx" protection="All" timeout="60">
    </forms>
</authentication>
<authorization>
    <deny users="?"/>
</authorization>

我对这些东西还比较陌生,因此可以提供任何帮助.谢谢!

I am relatively new to this stuff, so any help is appreciated. Thanks!

推荐答案

它将在下一个请求时更新,但不会在其后的下一行更新. RedirectFromLoginPage 在客户端浏览器中设置身份验证cookie阅读下一个客户端请求,您将看到User.Identity.Name属性已更新.在同一HTTP请求中更新此属性毫无意义,因为您已经知道用户在调用方法时通过了身份验证.

It will be updated on the next request but not on the next line following it. RedirectFromLoginPage sets an authentication cookie in the client browser that will be read upon the next client request and you will see the User.Identity.Name property updated. Updating this property in the same HTTP request is meaningless as you already know that the user passed authentication as you called the method.

这篇关于RedirectFromLoginPage()未更新User.Identity.Name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆