.net Access Forms authentication "timeout" value in code

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?


我认为你可以从FormsAuthentication静态类方法中读取它,这比直接读取web.config更好,因为你可能从更高级别的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);
链接地址: http://www.djcxy.com/p/48150.html

上一篇: ASP.Net MVC自定义身份验证

下一篇: .net访问表单身份验证代码中的“超时”值