RE: How do I keep a FormsAuthenticationTicket up to date ?
From: Jonathan Ruckert (jruckert_AT_novaworks_DOT_com_DOT_au)
Date: 03/25/04
- Next message: Dimitris Papadimitriou: "Re: signing small pieces of data"
- Previous message: Ken Schaefer: "Re: Windows Auth -- double hop issue??"
- In reply to: Fresh Air Rider: "How do I keep a FormsAuthenticationTicket up to date ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 24 Mar 2004 19:06:06 -0800
In the Global.asax file find the following function and modify to suit, this should be what you are looking for.
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
// Get Forms Identity From Current User
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
// Get Forms Ticket From Identity object
FormsAuthenticationTicket ticket = id.Ticket;
// Retrieve stored user-data (our roles from db)
string userData = ticket.UserData;
// UPDATE USER ROLES HERE WITH DB ETC.
// Create a new Generic Principal Instance and assign to Current User
HttpContext.Current.User = new GenericPrincipal(id, roles);
}
}
}
}
Cheers,
Jonathan Ruckert
----- Fresh Air Rider wrote: -----
Hi All
I have written a website in DotNet (C#) which uses Role-based Security
with Forms Authentication
When a user logs in, their roles are retrieved from a SQL Server
database and an authentication ticket is created.
My only problem is that a User should only have to login every few
months but I want any changes made to a users permissions record in
the database to be picked up every time the user logs in.
In other words, if a user has been granted an "Admin" role and then
has this role revoked because they have misused it, I want the user to
be prevented from accessing the "Administration" area next time he or
she accesses the website.
I'm guessing that I Would need to update the
FormsAuthenticationTicket, possibly within the Session_Start section
of Global.asax.cs
If anyone could please give me some advice or a URL of an article
which covers this then I would be very grateful.
Many thanks in advance
John
- Next message: Dimitris Papadimitriou: "Re: signing small pieces of data"
- Previous message: Ken Schaefer: "Re: Windows Auth -- double hop issue??"
- In reply to: Fresh Air Rider: "How do I keep a FormsAuthenticationTicket up to date ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|