Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
whats wrong with this coding, its not working for me
Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick{
if(e.Item.Text.ToLower()=="Logout"){
Session.Abandon()
Session.Contents.RemoveAll()
System.Web.Security.FormsAuthentication.SignOut()
Response.Redirect("index.aspx")
}
}
End If
End Sub
Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick{
if(e.Item.Text.ToLower()=="Logout"){
Session.Abandon()
Session.Contents.RemoveAll()
System.Web.Security.FormsAuthentication.SignOut()
Response.Redirect("index.aspx")
}
}
Did you try keeping a break point over the MenuItemClick event?
After you get near below line, it fails because e.Item.Text.ToLower() gives you all letters in lower case i.e.,
if(e.Item.Text.ToLower()=="Logout") should beif(e.Item.Text.ToLower()=="logout")
Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
Put the above code in the Page_Load of your Logout.aspx :)
As a side note, when comparing strings, check out e.Item.Text.Equals("Logout", StringComparison.CurrentCultureIgnoreCase). This will save you creating another variable in terms of when you call .ToLower()
Dont forget to click "Mark as answer" on the post that helped you.
================================================
Why catch a fish to feed someone, when you can teach them to fish and they can feed themselves
mveriya
Member
5 Points
28 Posts
code used for 'logout' in menu item
Jun 27, 2010 05:32 PM|LINK
whats do i have to do if i want to logout from the menu item i'v created as 'logout'
ASP.NET Visual web developer
andrewjboyd
Contributor
4426 Points
864 Posts
Re: code used for 'logout' in menu item
Jun 27, 2010 10:18 PM|LINK
FormsAuthentication.SignOut()
Will log you out, then you can redirect to where ever seems logical
================================================
Why catch a fish to feed someone, when you can teach them to fish and they can feed themselves
mveriya
Member
5 Points
28 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 11:22 AM|LINK
where do i enter that?
sundeep_38
Contributor
3541 Points
604 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 11:29 AM|LINK
Hi,
If its menu control, can write it in "OnMenuItemClick"
protected void OnMenuItemClick(object sender, MenuEventArgs e)
{
if(e.Item.Text.ToLower() == "logout")
{
FormsAuthentication.SignOut();
Session.Abandon();
//Redirect the page.
}
}
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
mveriya
Member
5 Points
28 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 02:53 PM|LINK
whats wrong with this coding, its not working for me
Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick{
if(e.Item.Text.ToLower()=="Logout"){
Session.Abandon()
Session.Contents.RemoveAll()
System.Web.Security.FormsAuthentication.SignOut()
Response.Redirect("index.aspx")
}
}
End If
End Sub
sundeep_38
Contributor
3541 Points
604 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 06:33 PM|LINK
Did you try keeping a break point over the MenuItemClick event?
After you get near below line, it fails because e.Item.Text.ToLower() gives you all letters in lower case i.e.,
if(e.Item.Text.ToLower()=="Logout") should be if(e.Item.Text.ToLower()=="logout")
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
mveriya
Member
5 Points
28 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 08:28 PM|LINK
but my list item is like this
<asp:MenuItem NavigateUrl="~/logout.aspx" Text="Logout" Value="Logout">
andrewjboyd
Contributor
4426 Points
864 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 10:30 PM|LINK
Put the above code in the Page_Load of your Logout.aspx :)
As a side note, when comparing strings, check out e.Item.Text.Equals("Logout", StringComparison.CurrentCultureIgnoreCase). This will save you creating another variable in terms of when you call .ToLower()
================================================
Why catch a fish to feed someone, when you can teach them to fish and they can feed themselves
mveriya
Member
5 Points
28 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 10:37 PM|LINK
do i even need a logout.aspx page?
since i am redirecting to index.aspx page?
andrewjboyd
Contributor
4426 Points
864 Posts
Re: code used for 'logout' in menu item
Jun 28, 2010 10:39 PM|LINK
I prefer it, it keeps your logout code in one central location :)
================================================
Why catch a fish to feed someone, when you can teach them to fish and they can feed themselves