Membership.GetUser gets called from Page_Load when user is logging out? How to prevent this?
this is probably the way it is supposed to happen, but I have an aspx page and in the page load event, I am calling MembershipUser user = Membership.GetUser() which gets the informat开发者_高级运维ion for the currently logged in user. Now this works fine if I don't have a master page, but in this case, the page is associated with a master page. What is happening is that when the page is first visited, the user is logged in, so Membership.GetUser() works fine, but when the user clicks on the logout link from the asp.net login control, it calls page load of the aspx page again which in turn calls Membership.GetUser() which now returns null and causes an error.
Am I calling Membership.GetUser in an incorrect place? I am not not sure what to do?
Do I just have to check if the Membership.GetUser() returns null? Is it that simple?
If the page is visible to both anonymous and authenticated users, then you will need to check if GetUser returns null, or check User.Identity.IsAuthenticated.
If the page shouldn't be visible for anonymous users, you could tie into the LoggedOut event of the LoginStatus control and redirect the user to an appropriate page.
精彩评论