Page.User.Identity.Name获取不到值

在一个页面中写入:

 FormsAuthentication.SetAuthCookie(username, true);

在另一个页面中写入:

string name = Page.User.Identity.Name;

获取不到值的原因:

在web.config中加入:

<authentication mode="Forms">
<forms loginUrl="XXX.aspx" timeout="XXX" />
</authentication>

原文地址:https://www.cnblogs.com/zhangtingzu/p/5474549.html