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


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



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?




ASP.NET MVC - HTML.BeginForm and SSL

1:



asp.net mvc IDataErrorInfo validation when using ViewModel
Yes, you could do that.


How to make data available when one Controller's View calls another Controller's View?
You would need to generate the authentication ticket manually instead of letting the framework generate it automatically..
Is WPF and MVC same concepts?
Depending the user role, the expiration you assign to the ticket..
jQUERY onclick post
This tutorial show how to generate the ticket manually..
What is the best way to store WMD input/markdown in SQL server and display later?


OutOfMemoryException C# When Uploading Image Files


Using HttpContext.Current.Application to store simple data

2:


SNIPPET:.
     switch Role:       Case A: VARIABLE X = Y; BREAK;      CASE B: VARIABLE X = Y2; BREAK;      .. 

End switch FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // Ticket version Username.Value, // Username associated with ticket DateTime.Now, // Date/time issued DateTime.Now.AddMinutes(VARIABLE X), // Date/time to expire true, // "true" for a persistent user cookie reader.GetString(0), // User-data, in this case the roles FormsAuthentication.FormsCookiePath);// Path cookie valid for // Encrypt the cookie using the machine key for secure transport string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie( FormsAuthentication.FormsCookieName, // Name of auth cookie hash); // Hashed ticket // Set the cookie's expiration time to the tickets expiration time if (ticket.IsPersistent) cookie.Expires = ticket.Expiration; Response.Cookies.Add(cookie);



68 out of 100 based on 53 user ratings 778 reviews

@