3
votes

I have a testwebsite in which I've made the Loginstatus to be

[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect"     LogoutText="Log Out" LogoutPageUrl="Account/Logout.aspx"/> ]

However when I click the Log Out on the screen .. it goes to this url and doesn't actually call the logout page.

"http://localhost/TestWebSite/Account/Login.aspx?ReturnUrl=%2fTestWebSite%2fAccount%2fLogout.aspx"

I was trying to make it call some logic to logout and remove a db row I have for my custom membership Provider. This logic was placed in the page load of the logout.aspx.cs

Session.RemoveAll();

FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

but of course it's not being called... and of course if I login again with the ReturnUrl there, it immediately calls the logout page. I'm confused since this is not the behavior that I expected nor is documented.

Please help.

Thanks!

1
Are you sure its not loading the logout page, then immediately redirecting to the login page, using the logout page as the return url? What happens if you remove the redirect, or redirect to another page instead?Kyle Trauberman
I put a break point on the Page_Load and it's not hitting it. If I leave that breakpoint and login again with the returnurl on the link, it DOES hit the breakpoint. So I'm pretty sure it's not hitting the page.DavieDave
I downloaded Fiddler... I see what's happening... When it calls the Logout.aspx It returns a 302 (Object moved to here) and immediately goes to the login page with the returnurl... Any ideas?DavieDave
(probably a stupid question:) Are you logged in when you go to the logout page? If not and the app is configured to require authentication, ASP.NET will automatically take you to the login page without hitting your break point, using a return url for the page you attempted to access (the logout page in this case).Kyle Trauberman

1 Answers

2
votes

I'm not sure if this is what your looking for but if you simply want to run some code after the user has logged out then use this method http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginstatus.onloggedout.aspx

It is called when the user presses the logout button and has been logged out. You can put your code there and then redirect to your logout page if you'd like.

Note: Theres also this method which you can use to make sure the user meets certain conditions when logging out and even cancel logging out. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginstatus.onloggingout.aspx

Hope this helps.