2012-09-14 68 views
0

我使用的Site.Master文件來創建日誌/使用下面的代碼註銷現場每一頁上:ASP.NET註銷事件處理程序和頁面的Site.Master

<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; 

顯然Site.Master.cs不工作(用戶不存在的情況下)。有沒有其他方式來檢索用戶信息?另外,有沒有一種方法可以從用戶點擊「註銷」頁面傳輸信息(例如使用查詢字符串)?

謝謝

回答

1

類似這樣的東西你在找什麼?

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

或者如果你只需要用戶名...

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