3

I was just working with FormsAuthentication and I wanted the value of timeout property of form authentication tag in web config. In 4.0 we can get this via FormsAuthentication.Timeout.TotalMinutes (ref: FormsAuthenticationTicket.expiration v web.config value timeout) Can you let me know how can I get the same in .NET 2.0?

1 Answer 1

6

Take a look at this issue on Microsoft's Connect site. It was closed as "Won't Fix", but it looks like it's been fixed in .NET 4.

One way of doing it in .NET 2.0 or 3.x is to issue and inspect a FormsAuthentication ticket:

FormsAuthentication.SetAuthCookie("user", false);
HttpCookie cookie = (HttpCookie)(Request.Cookies[FormsAuthentication.FormsCookieName]);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
int timeoutInMinutes = (ticket.Expiration - ticket.IssueDate).TotalMinutes; 

Another is to use the configuration APIs:

Configuration config = Configuration.OpenWebConfiguration(HttpRuntime.AppDomainAppPath);
AuthenticationSection section = 
    (AuthenticationSection)config.GetSection("system.web/authentication");
int timeout = section.Forms.Timeout.TotalMinutes;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.