Setting auth cookie timeout length based on role in ASP.NET

asp.net, asp.net-mvc, cookies, forms-authentication, roles

Solution

Yes, you could do that. You would need to generate the authentication ticket manually instead of letting the framework generate it automatically.

Depending the user role, the expiration you assign to the ticket.

This tutorial show how to generate the ticket manually.

Problem

I want to allow admins to be logged in for longer than normal users. I don't see a hook for setting the cookie timeout programmatically or in a role-based way. Is this possible in ASP using Forms Authentication?

Original source