Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASPX auth cookie过期时间始终为30分钟_C#_Asp.net_Iis 7.5_Asp.net 4.0 - Fatal编程技术网

C# ASPX auth cookie过期时间始终为30分钟

C# ASPX auth cookie过期时间始终为30分钟,c#,asp.net,iis-7.5,asp.net-4.0,C#,Asp.net,Iis 7.5,Asp.net 4.0,我已将cookie过期时间设置为1个月,但当我在浏览器中查看.ASPXAUTH cookie的过期超时时,它会显示从现在起提前30分钟 var ticket = new FormsAuthenticationTicket(1, "myname", DateTime.Now, DateTime.Now.AddMonths(1), true, "test"); string ticketS

我已将cookie过期时间设置为1个月,但当我在浏览器中查看.ASPXAUTH cookie的过期超时时,它会显示从现在起提前30分钟

var ticket = new FormsAuthenticationTicket(1, "myname", DateTime.Now,
                                                        DateTime.Now.AddMonths(1), true, "test");
string ticketString = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString)
                 {
                     Expires = DateTime.Now.AddMonths(1),
                     Path = FormsAuthentication.FormsCookiePath
                 };
HttpContext.Current.Response.Cookies.Add(cookie);

您能告诉我为什么上面的代码会出现这种情况吗?我想更改过期时间,但它总是在30分钟后出现。

您需要以编程方式设置此超时,还是可以在配置文件中设置它?有一个timeout参数,表示身份验证cookie超时:

此参数的默认值为30分钟

致以最良好的祝愿,
Dmitry

检查web.config文件,在下面的元素system.web->authentication下应该有表单条目

检查超时属性,是否设置为30分钟


从那里删除此表单身份验证标签。

以及我链接到的其他答案中的建议

显然,在ASP.NET中,它会在Web.config中检查过期时间,而不会从cookie中获取过期时间。因此,您需要添加到
中的配置文件中:



您在哪里指定了1个月?您有任何理由手动创建身份验证票证吗?如果您自动执行此操作,您可以通过web.config.V4Vendetta处理到期时间。他在这里执行此操作:“DateTime.Now.AddMonths(1)”到Rocky Singh,您是否检查了slidingExpiration=“false”属性?我猜你没有指定它为false或者它不存在。在这种情况下,每个请求都会将Web.config中的过期时间重置为默认值。我想将slidingExpiration保持为true,同时覆盖过期时间(默认为30分钟)。只需尝试将域添加到表单标记(任何字符串),我也遇到了同样的问题,我必须将其设置为240分钟,我在web.config和代码中创建了相同的条目,并在表单标记中添加了域。我还将IIS中的应用程序池超时设置为240分钟。
<authentication mode="Forms">
  <forms
 name=".ASPXAUTH"
 loginUrl="Login.cshtml" //your login page
 defaultUrl="Default.cshtml" //your default page
 protection="All" //type of encryption
 timeout="43200" //a month in minutes
 path="/"
 requireSSL="false"
 slidingExpiration="true" //Every refresh the expiration time will reset
 cookieless="UseDeviceProfile" //Use cookies if the browser supports cookies
 domain=""
 enableCrossAppRedirects="false">
    <credentials passwordFormat="SHA1" />
  </forms>
</authentication>