FormsAuthenticationTicket on a server

J

JTourvieille

Hi,
Does any one knows how to list all FormsAuthenticationTicket available
on a server?
Thanks
 
G

Guest

You try something like this.

HttpCookie cookie = Response.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

You could also access specific tickets user in a HttpModule by hooking
and using an interface IHttpModule.
You will also need to add a refereance to web.config for your HttpModule.

Good Luck

public class FormsAuthSessionEnforcement : IHttpModule
{
private static string _provider = "FiPort_MembershipProvider";

public FormsAuthSessionEnforcement() { }

public void Init(HttpApplication context)
{
context.PostAuthenticateRequest += new
EventHandler(OnPostAuthenticate);
}

private void OnPostAuthenticate(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = app.Context;

//If the user was authenticated with Forms Authentication
//Then check the session ID.
if (context.User.Identity.IsAuthenticated == true)
{
if (context.User.IsInRole("ServiceProviders"))
{
_provider = "FiPort_MembershipProviderEx";
}

FormsAuthenticationTicket authTicket =
((FormsIdentity)context.User.Identity).Ticket;

Guid guid = new Guid(authTicket.UserData);

MembershipUser loginUser =
Membership.Providers[_provider].GetUser(authTicket.Name, false);
Guid currentSession;
//If there isn't any session information in Membership at
this point
//then it is likely the user logged out, and an old cookie is
//being replayed.
if (!String.IsNullOrEmpty(loginUser.Comment))
{
string currentSessionString =
loginUser.Comment.Split("|".ToCharArray())[1];
currentSession = new
Guid(currentSessionString.Split(";".ToCharArray())[1]);
}
else
{
currentSession = Guid.Empty;
}
//If the session in the cookie does not match the current
session as stored
//in the Membership database, then terminate this request
if (guid != currentSession)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}

}
}

public void Dispose() { }

}
 

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

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top