Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET LoginStatus inside LoginView doesn't trigger LoggingOut event

I have a LoginView in my APS.NET application with AnonymousTemplate and LoggedInTemplate. I've put LoginStatus control inside LoggedInTemplate but it doesn't work as expected.

Here's the code

<asp:LoginView ID="LoginView1" runat="server">
    <AnonymousTemplate>
        <asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate"
            DisplayRememberMe="False" PasswordRecoveryUrl="/" 
            DestinationPageUrl="/">
        </asp:Login>
    </AnonymousTemplate>
    <LoggedInTemplate>
        You are logged in as 
        <asp:LoginName ID="LoginName1" runat="Server"></asp:LoginName>.
        <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" 
            LogoutPageUrl="/" onloggingout="LoginStatus1_LoggingOut" />
    </LoggedInTemplate>
</asp:LoginView>

All event handlers are correctly defined in code behind file.

The problem is that if user logs in he will see his user name with logout link from LoginStatus control. Clicking the logout link takes the user back to login form (both login and logout form are part of the same user control) but if I refresh the page the user is still logged in.

I've noticed that if I move LoginStatus control outside the LoginView then logout process works as expected. I've also noticed that when LoginStatus is inside LoginView then it doesn't raise a loggingout event.

Does anyone have any ideas what might be the problem?

like image 868
RaYell Avatar asked Aug 11 '10 09:08

RaYell


3 Answers

I'm running into the same issues here. The loginstatus control outside of the loginview control works as desired. It seems silly that it won't work within the loginview control.

EDIT** OK, so I left out that I was building this page in Sitecore. Apparently Sitecore somehow meddels with the loginview control and must be added to the following section in the web.config:

  <sitecore>
    <rendering>
      <typesThatShouldNotBeExpanded>
        <type>System.Web.UI.WebControls.LoginView</type>
      </typesThatShouldNotBeExpanded>
    </rendering>
  </sitecore>

Thank some other guy...

-Victor F.

like image 151
VFein Avatar answered Oct 23 '22 21:10

VFein


FormsAuthentication.SignOut()
FormsAuthentication.RedirectToLoginPage()

Also have you used form authentication in proper way i mean did you put a web config in inner directories?

<system.web>
<authorization>
  <allow users="?"/>
</authorization>

like image 24
Manish Prajapati Avatar answered Oct 23 '22 19:10

Manish Prajapati


I am experiencing the same problem. But my solution was to swap out the loginstatus control for a hyperlink control and have the hyperlink navigate to my home page with a querystring parameter attached like "logout=true" and then on my home page check Request.QueryString for the value and if it is not null the do this.

FormsAuthentication.SignOut();
like image 42
Raheem Avatar answered Oct 23 '22 21:10

Raheem