FormsAuthentication.Timeout.TotalMinutes in .NET 3.5

I just worked with FormsAuthentication and I need the value of the timeout property of the form authentication tag in the web configuration. In 4.0, we can get this through FormsAuthentication.Timeout.TotalMinutes (ref: FormsAuthenticationTicket.expiration v web.config value timeout ) Can you tell me how I can get the same in .NET 2.0?

+3
Mar 07 2018-12-12T00:
source share
1 answer

See this issue on the Microsoft Connect website . It was closed as "Do not fix", but it looks like it was fixed in .NET 4.

One way to do this in .NET 2.0 or 3.x is to issue and validate 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 API:

 Configuration config = Configuration.OpenWebConfiguration(HttpRuntime.AppDomainAppPath); AuthenticationSection section = (AuthenticationSection)config.GetSection("system.web/authentication"); int timeout = section.Forms.Timeout.TotalMinutes; 
+6
Mar 07 '12 at 11:25
source share



All Articles