ASP.NET注销事件处理程序和站点.母版页



我正在使用一个站点。使用以下代码在每个页面上创建登录/注销字段的主文件:

<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false" >
                <AnonymousTemplate>
                    [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                </AnonymousTemplate>
                <LoggedInTemplate>
                    Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                    [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" OnLoggedOut="LoginStatus1_LoggedOut" LogoutPageUrl="~/"/> ]
                </LoggedInTemplate>
</asp:LoginView>

但是,当用户注销时,我希望能够运行事件处理程序

OnLoggedOut="LoginStatus1_LoggedOut" 

并编辑用户表中的一些信息(例如上次注销时间和其他信息)。然而,我不知道如何检索这些信息,因为

FormsIdentity id = (FormsIdentity)User.Identity;

显然在现场不起作用。Master.cs(上下文中不存在用户)。是否有其他方法可以检索用户信息?此外,是否有方法从用户单击"注销"的页面传输信息(例如使用querystring)?

感谢

你在找这样的东西吗?

System.Security.Principal.IIdentity id = HttpContext.Current.User.Identity;

或者,如果您只需要用户名。。。

String id = HttpContext.Current.User.Identity.Name

最新更新