问题描述
我只是工作与FormsAuthentication,我想形式的认证标签的web配置超时属性的值。在4.0,我们可以通过FormsAuthentication.Timeout.TotalMinutes(得到这个编号:FormsAuthenticationTicket.expiration v web.config中值超时),你可以让我知道我怎样才能在.NET 2.0一样的吗?
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?
推荐答案
看看this问题在微软Connect网站。它被关闭,不会修复,但它看起来像它被固定在.NET 4中。
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.
一做在.NET 2.0或3.x版的方式是发行和检查一个FormsAuthentication票:
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;
另一种是使用配置API:
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;
这篇关于在.NET 3.5 FormsAuthentication.Timeout.TotalMinutes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!