I'm adding a logout expiration alert to my application and would like to access my web.config forms authentication "timeout" value from my code. Any way i could do this?
I think you can read it from the FormsAuthentication static class methods, which would be better than doing it by reading the web.config directly as you may be inheriting authentication settings from a higher level web.config.
var authTicket = new FormsAuthenticationTicket(user.EmailAddress, true, (int)FormsAuthentication.Timeout.TotalMinutes);
You can access the web.config's timeout
value in:
FormsAuthentication.Timeout.TotalMinutes
I don't know since when it's available, I'm using .NET 4.5.
Configuration conn = WebConfigurationManager.OpenWebConfiguration("");
AuthenticationSection section = (AuthenticationSection)conn.SectionGroups.Get("system.web").Sections.Get("authentication");
long cookieExpires = System.Convert.ToInt64(section.Forms.Timeout.TotalMinutes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With