473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SignOut not working due to multiple encrypted TicketCookies?

Ok, I spend now half the night to get this working. And actuallyit works, the only problem is, my user can't sign out anymore.

Here is what I'm doing: I've got a web-app which has twosubdirectories: AdminArea and EditorArea, to which access isrestricted per role. Here an excerpt from my web.config:

<location path="EditorArea">
<system.web>
<authorization>
<allow roles="Editors" />
<deny users="*" />
</authorization>
</system.web>
</location>

Ok, and here goes the code which executes, whenever the user hitsthe logon button (the details of validating username andpassword are omitted):

// the user (sUser) is valid, password correct...
FormsAuthenticationTicket ticket = newFormsAuthenticationTicket(
1,
sUser,
DateTime.Now,
DateTime.Now.AddMinutes(20),
false,
sRole,
FormsAuthentication.FormsCookiePath);

string sEncTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = newHttpCookie(FormsAuthentication.FormsCookieName, sEncTicket);
Context.Response.Cookies.Add(cookie);

Response.Redirect(sTargetURL);

What happens here is that I fetch the Role this user belongs tofrom a Database and add it to the UserData field of the ticket,so that I don't have to go check everytime the user requests apage.

Next thing is to authenticate each page request. Here is theevent handler in my global.asax:

protected void Application_AuthenticateRequest(Object sender,EventArgs e) {

if(Request.IsAuthenticated) {

string[] sRoles = new string[1];

FormsAuthenticationTicket ticket =
FormsAuthentication.Decrypt(Request.Cookies.Get(Fo rmsAuthentication.FormsCookieName).Value);

if (ticket == null) {
throw new Exception("Authorisation Ticket invalid!");
}

sRoles[0] = ticket.UserData;

Context.User = new System.Security.Principal.GenericPrincipal(newForm sIdentity(ticket), sRoles);
}
}

Fine, it works. Only Admins can access the AdminArea and so on.But now I'm getting wild, because I want to add a Logoff. SayI've got a page that is called "AdminDefault.aspx". After thesuccessful logon, the (Admin-) User is redirected to this page.On the page is a button called sign out, which, in its clickhandler, transfers the user to the logout page, which actuallywill attempt to perform the logout using this:

FormsAuthentication.SignOut();
Response.Cookies.Clear(); // try harder
Response.Redirect("Logon.aspx", true);</code>

If you are as tired as I am by know, you'll just try <i>anything</i>to get rid of the *?%"-cookies. The problem is, thatwhatever I do, the cookies remain (or are re-injected into theresponse?). I simply can't log out. I'm transfered to thelogon.aspx page, and looking at the trace I see that I received2 (TWO) encrypted cookies which belong to FormsAuthentication.

I really, really would be glad if somebody could shed some lightand send me to bed X|

Matthias

--------------------------------
From: Matthias Steinbart

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>HY4vabdrzUymddk5c1H5vw==</Id>
Nov 19 '05 #1
0 1033

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff Johnson | last post by:
I'm using forms authentication to protect a subfolder within my site. I've got it working fine except for two issues: (1) When I do a RedirectFromLogin page I have to put a cookie path ("/"...
0
by: Ed West | last post by:
Hello This SignOut code is not working, any ideas? TIA. public class logout : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { FormsAuthentication.SignOut();...
8
by: den 2005 | last post by:
Hi everybody, I am not sure where to put this in this forum. So, I posted this at several topics. I created a class library that has two public methods Encrypt() and Decrypt(). I reference this...
2
by: parez | last post by:
Hi ALl, I had problem with FormsAuthentication.SignOut(). It wasnt working. Looked arround and saw a lot of posts and different solutions to the problem. And some how (i dont nkow what...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.