+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Cannot Logout

Cannot Logout

6 posts, 0 answered
  1. aung maw
    aung maw avatar
    14 posts
    Registered:
    07 Apr 2006
    22 Apr 2009
    Link to this post

    Hi, I'm putting logout button which executes the following method and it doesn't logout and always redirecting to the same page.  I'm using Sitefinity Community Master Templates.  Please help.
    Thanks,

     

    protected

     

    void logoutButton_Click(object sender, System.EventArgs e)

     

    {

    System.Web.Security.

    FormsAuthentication.SignOut();

     

    Response.Redirect(

    "~/Sitefinity/Login.aspx");

     

    }

    code inside Master Page


    <
    asp:LinkButton ID="logoutButton" CausesValidation="false" Text="Logout" OnClick="logoutButton_Click" runat="server"></asp:LinkButton>

     

     

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Apr 2009
    Link to this post
    Hi aung maw,

    As I see i,t it is the code from Admin.master page. Are you using it on another page. The codes is correct and you should be logged out and redirected to Login.aspx page. You can give a try by crating a new link and use FromsAuthentication.SignOut() for it.

    <li>&nbsp;|&nbsp;<asp:LinkButton ID="LinkButton1" CausesValidation="false"   
                                    ToolTip="Logout1" Text="Logout1" runat="server" onclick="LinkButton1_Click"></asp:LinkButton></li

    Make redirect in the code behind.

     protected void LinkButton1_Click(object sender, EventArgs e) 
        { 
            FormsAuthentication.SignOut(); 
            Response.Redirect("http://www.yahoo.com"); 
        } 


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. aung maw
    aung maw avatar
    14 posts
    Registered:
    07 Apr 2006
    23 Apr 2009
    Link to this post

    Thanks Ivan, Yes I'm using it on CommunityHome Master template.  I put the code you suggested but still does not work.  It doesn't logout and stays on the same page after the postback.

    Regards,

     

     

    protected void LinkButton1_Click(object sender, EventArgs e)

     

    {

     

    FormsAuthentication.SignOut();

     

    Response.Redirect(

    "http://www.yahoo.com");

     

    }

     




    <%

    @ Master Language="C#" AutoEventWireup="true" CodeFile="CommunityHome.master.cs" Inherits="App_Master_MasterPage" %>

     

     

     

    <!

     

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

    <

     

    script runat="server">

     

    </

     

    script>

     

    <

     

    html xmlns="http://www.w3.org/1999/xhtml" >

     

    <

     

    head id="Head1" runat="server">

     

     

    <title>Untitled Page</title>

     

     

     

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

     

    </

     

    head>

     

    <

     

    body class="home">

     

     

    <form id="form1" runat="server">

     

     

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

     

     

    <div class="wrapper">

     

     

    <div class="wrapperIn">

     

     

    <div class="navigation">

     

     

    <asp:contentplaceholder id="TopMenu" runat="server"></asp:contentplaceholder>

     

     

    </div>

     

     

    <div class="header">

     

     

    <h1><asp:contentplaceholder id="UserGroup" runat="server"></asp:contentplaceholder></h1>

     

    <%

    -- <div class="breadcrumb">

     

    <asp:contentplaceholder id="Breadcrumb" runat="server"></asp:contentplaceholder>

    </div>--

     

    %>

     

     

    <p class="userGroupLogo">

     

     

    <img id="Img1" src="~/App_Themes/ModernLight/Images/UserGroupLogo.gif" runat="server" alt="UserGroup Logo" />

     

     

    </p>

     

     

    <div class="searchbox">

     

     

    <asp:contentplaceholder id="SearchBox" runat="server"></asp:contentplaceholder>

     

     

    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>

     

     

    </div>

     

     

    </div>

     

     

    <div class="content">

     

     

    <div class="main">

     

     

    <h2>

     

     

    <asp:contentplaceholder id="PageTitle" runat="server"></asp:contentplaceholder>

     

     

    </h2>

     

     

    <div class="introductory">

     

     

    <asp:contentplaceholder id="IntroductoryContent" runat="server"></asp:contentplaceholder>

     

     

    </div>

     

     

    <h2 class="whatsNew">

     

     

    <strong><asp:contentplaceholder id="WhatsNew" runat="server"></asp:contentplaceholder></strong>

     

     

    </h2>

     

     

    <div class="recentActivities">

     

     

    <div class="recentActivityBoxWrapperDouble">

     

     

    <asp:contentplaceholder id="RecentActivityBox1" runat="server"></asp:contentplaceholder>

     

     

    </div>

     

     

    <div class="clear"><!-- --></div>

     

     

    <div class="recentActivityBoxWrapper">

     

     

    <div class="recentActivityBox">

     

     

    <asp:contentplaceholder id="RecentActivityBox3" runat="server"></asp:contentplaceholder>

     

     

    </div>

     

     

    <div class="recentActivityBox">

     

     

    <asp:contentplaceholder id="RecentActivityBox4" runat="server"></asp:contentplaceholder>

     

     

    </div>

     

     

    </div>

     

     

    <div class="clear"><!-- --></div>

     

     

    </div>

     

     

    <div class="recentActivitiesBottom"><!-- --></div>

     

     

    </div>

     

     

    <div class="sidebar">

     

     

    <asp:contentplaceholder id="SideBarContent" runat="server"></asp:contentplaceholder>

     

     

    </div>

     

     

    <div class="footer">

     

     

    </div>

     

     

    </div>

     

     

    </div>

     

     

    </div>

     

     

    </form>

     

    </

     

    body>

     

    </

     

    html>

     

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Apr 2009
    Link to this post
    Hello aung maw,

    As I see it form the code you have sent there is not event that fires the SitegnOut().

    Your code:

    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>  

    You need to add an event on button click.

    Here is a working sample that you can test:

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default2.master.cs" Inherits="App_Master_Default2" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
        <asp:ContentPlaceHolder id="head" runat="server"
        </asp:ContentPlaceHolder> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
           
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"
            <asp:LinkButton ID="LinkButton1" runat="server" Text="Logout"  
                    onclick="LinkButton1_Click"></asp:LinkButton> 
            </asp:ContentPlaceHolder> 
              <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server"
            <asp:Label id="label" runat="server"></asp:Label> 
             </asp:ContentPlaceHolder> 
        </div> 
        </form> 
    </body> 
    </html> 

    code behind

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.Security; 
    using Telerik.Security; 
     
    public partial class App_Master_Default2 : System.Web.UI.MasterPage 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            this.label.Text = "Currnetly logged user is: &nbsp;" + UserManager.GetCurrentUserName().ToString(); 
        } 
        protected void LinkButton1_Click(object sender, EventArgs e) 
        { 
            if (Page.User.Identity.IsAuthenticated) 
            { 
                FormsAuthentication.SignOut(); 
                Response.Redirect("http://www.yahoo.com"); 
            } 
            else
                this.label.Text = "You are not authenticated"
            } 
        } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. aung maw
    aung maw avatar
    14 posts
    Registered:
    07 Apr 2006
    24 Apr 2009
    Link to this post
    Hi Ivan, It is working now. Thanks so much!  Regards,
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Apr 2009
    Link to this post
    Hello aung maw,

    I am glad to hear that you have managed to get the code working.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
6 posts, 0 answered