在.NET 3.5 FormsAuthentication.Timeout.TotalMinutes [英] FormsAuthentication.Timeout.TotalMinutes in .NET 3.5

查看:627
本文介绍了在.NET 3.5 FormsAuthentication.Timeout.TotalMinutes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是工作与FormsAuthentication,我想形式的认证标签的web配置超时属性的值。在4.0,我们可以通过FormsAuthentication.Timeout.TotalMinutes(得到这个编号:<一href="http://stackoverflow.com/questions/5171637/formsauthenticationticket-expiration-v-web-config-value-timeout">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?

推荐答案

看看<一href="https://connect.microsoft.com/VisualStudio/feedback/details/102290/expose-forms-authentication-timeout-as-a-public-static-property">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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆