Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net Access Forms authentication "timeout" value in code

Tags:

c#

.net

asp.net

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?

like image 775
aaron Avatar asked May 08 '09 19:05

aaron


3 Answers

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);
like image 116
cjk Avatar answered Nov 03 '22 05:11

cjk


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.

like image 7
Luiz Damim Avatar answered Nov 03 '22 05:11

Luiz Damim


 Configuration conn = WebConfigurationManager.OpenWebConfiguration("");

            AuthenticationSection section = (AuthenticationSection)conn.SectionGroups.Get("system.web").Sections.Get("authentication");



            long cookieExpires = System.Convert.ToInt64(section.Forms.Timeout.TotalMinutes);
like image 4
Will Avatar answered Nov 03 '22 04:11

Will