ASP.NET注销事件处理程序和Site.Master页
我正在使用Site.Master文件在每个页面上使用以下代码创建登录/注销字段:ASP.NET注销事件处理程序和Site.Master页,asp.net,forms,web,Asp.net,Forms,Web,我正在使用Site.Master文件在每个页面上使用以下代码创建登录/注销字段: <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false" > <AnonymousTemplate> [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="se
<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>
并编辑用户表中的某些信息(例如上次注销时间等)。但是,我不知道如何检索这些信息,因为
FormsIdentity id = (FormsIdentity)User.Identity;
显然在Site.Master.cs中不起作用(上下文中不存在用户)。是否有其他方法检索用户信息?此外,是否有方法从用户单击“注销”的页面传输信息(例如使用querystring)
谢谢你要找这样的东西吗
System.Security.Principal.IIdentity id = HttpContext.Current.User.Identity;
或者如果你只需要用户名
String id = HttpContext.Current.User.Identity.Name
String id = HttpContext.Current.User.Identity.Name