FormsAuthentication.SignOut() not working in UserControl

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

When i add the following code below to a userControl it doesn't fire.
Any ideas?


Sub SignOut(ByVal objSender As Object, ByVal objArgs As EventArgs)
FormsAuthentication.SignOut()
Response.Redirect(Request.UrlReferrer.ToString())
End Sub
<input id="cmdSignOut" type="submit" Value="Sign Out" runat="server"
onserverclick="SignOut"
NAME="cmdSignOut">
 
T

Teemu Keiski

Hi have you placed something to test the sub say Response.Write("I have been
clicked") to test that does the event handler run at all?
 
P

Patrick.O.Ige

Teemu thanks for the reply.
I tested it in an aspx page and it fires but doesn't in an ascx page.
 
T

Teemu Keiski

Is there anything special how you have the UC on the Page? Is it perhaps a
dynamical control?
 
P

Patrick.O.Ige

This is what i have :-
Top.ascx
------------
<%@ Control CodeBehind="_Header.ascx.vb" Language="vb"
AutoEventWireup="false" Inherits="Business.Commerce.C_Header" %>
' here i have some html and the Sign Out Button

Top.ascx.vb
-----------------
Public MustInherit Class C_Header
Inherits System.Web.UI.UserControl
' I placed the Sub Program here
End Class

Thats it.
 
P

Patrick.O.Ige

Teemu i tried putting in a
Response.Write and it fires!
Bu the FormsAuthentication.SignOut() doesn't fire:(

My UserControl class looks like this below thanks:-
Imports System.Web.Security

Public MustInherit Class C_Header

Inherits System.Web.UI.UserControl

Protected WithEvents cmdSignOut As
System.Web.UI.HtmlControls.HtmlInputButton

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

End Sub

Sub SignOut(ByVal objSender As Object, ByVal objArgs As EventArgs) Handles
cmdSignOut.ServerClick

'delete the users auth cookie and sign out

FormsAuthentication.SignOut()

'redirect the user to their referring page

'Response.Redirect(Request.UrlReferrer.ToString())

'Response.Write("hello")

End Sub

End Class
 
P

Patrick.O.Ige

After doing some testing i noticed the FormAuthentication.SignOut() button
fires on some page and doesn't on the others (Even when testing with the
Response.Write)
I have 3 usercontrols on the paage :- Header,Menu and Footer.
And the button is in the Header userControl.
When i click on a link in the menu(usercontrol) and a page opens up in the
body section and then click on the SignOut()Button in the
Header(usercontrol) sometimes it fires and if i do te same for another link
in the Menu it doesn't fire.
In my web.config in the location path i have some pages i DENY USERS ="?"
Any ideas what might be wrong?
 
T

Teemu Keiski

You should do a redirect after calling SignOut, for exampl to a general
logout.aspx page. At that point it has been request which has been made with
privileges so just doing SignOut does nothing but remove the authentication
cookie. Next request from that would be one without permissions and access.
 
P

Patrick.O.Ige

Im doing a Redirect after a SignOut()
Guess i uncommented it out by mistake in the code i posted...
Whats happening is that sometimes it fires sometimes not.
Thx
 
P

Patrick.O.Ige

Thx Teemu i got it working..
They were no FORM TAGS in the asp.net code arg!!!!( I was troubleshooting)
and again i changed it to an ASP:BUTTON.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,951
Messages
2,570,113
Members
46,698
Latest member
alexxx

Latest Threads

Top