C# 几天后,asp.net mvc页面重定向到登录页面

C# 几天后,asp.net mvc页面重定向到登录页面,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我有一个ASP.NET MVC页面,每5分钟刷新一次。此页面仅用于显示数据。用于承载此页面的PC数天都没有任何交互。该页面将刷新几天,但随后(自行)该页面将在2、4或5天后被重定向到登录页面 你知道发生了什么事吗 我在Web.config中为这个页面添加了以下属性,因为我认为可能是数据库在夜间运行备份时超时了,或者类似的奇怪情况 <location path="~/Views/Production/WIPScanStationViewer.aspx"> <system.web&

我有一个ASP.NET MVC页面,每5分钟刷新一次。此页面仅用于显示数据。用于承载此页面的PC数天都没有任何交互。该页面将刷新几天,但随后(自行)该页面将在2、4或5天后被重定向到登录页面

你知道发生了什么事吗

我在Web.config中为这个页面添加了以下属性,因为我认为可能是数据库在夜间运行备份时超时了,或者类似的奇怪情况

<location path="~/Views/Production/WIPScanStationViewer.aspx">
<system.web>
  <httpRuntime executionTimeout="1000" maxRequestLength="2048576"/>      
</system.web>    
</location>

您是否使用任何形式的身份验证/授权?如果是这样,这里的线索应该是重定向到登录屏幕。您的cookie可能会在X天之后过期。如果使用ASPNet身份检查
Startup.cs
>
Startup.ConfigureAuth(IAppBuilder应用程序)

app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
Provider=新CookieAuthenticationProvider
{
//允许应用程序在用户
//登录。这是一个安全功能,当您
//更改密码或向您的帐户添加外部登录名。
OnValidateIdentity=SecurityStampValidator
.OnValidateId实体


此外,如果cookie不是问题所在,您可能还需要在web.config中检查您的会话状态。请在此处查看这家伙。非常简单:

您的会话cookie似乎即将过期。请尝试打开该页面,按F12打开开发工具并转到“应用程序”选项卡。一旦出现,请展开“cookie”节点并搜索会话cookie。“Expires/Max Age”列应显示过期日期,以便您能够知道这是否是问题背后的原因

如果这就是问题所在,并且加载该页面的web浏览器永远不会关闭,则可以将该值更改为“Session”,这意味着该页面将没有过期日期,取而代之的是,cookie将在web浏览器关闭后立即过期


您也可以将cookie设置为在X天甚至几个月后过期,但老实说,我不太喜欢使用寿命很长的cookie,特别是因为如果cookie在任何时候被破坏,只要cookie没有过期,攻击者就可以访问您的会话。

应用程序池是否循环使用?是您的安全cookie吗过期?应用程序池正在循环使用。间隔设置为1740分钟,即29小时。但此页面有时会在长达5天的时间内不会重定向到登录页面。我不确定安全cookie是否过期。@我使用的是表单模式进行身份验证,而不是身份验证。我没有
Startup.cs
classSor哦,忘了正确地贴标签了@Adrian@Noahp您的票证或cookie是自动生成的吗?如果是,请检查您的web.config文件。我更新了我的答案,以显示一个示例
 app.UseCookieAuthentication(new CookieAuthenticationOptions 
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider 
        {
            // Enables the application to validate the security stamp when the user 
            // logs in. This is a security feature which is used when you 
            // change a password or add an external login to your account.  
            OnValidateIdentity = SecurityStampValidator
                .OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(30),
                regenerateIdentity: (manager, user) 
                => user.GenerateUserIdentityAsync(manager))
        }
    });
<!--
forms Attributes: 
name="[cookie name]" - Sets the name of the cookie used for Forms 
Authentication.
loginUrl="[url]" - Sets the URL to redirect client to for authentication.
protection="[All|None|Encryption|Validation]" - Sets the protection mode for 
data in cookie.
timeout="[minutes]" - Sets the duration of time for cookie to be valid 
(reset on each request).
path="/" - Sets the path for the cookie.
requireSSL="[true|false]" - Should the forms authentication cookie be sent 
only over SSL?
slidingExpiration="[true|false]" - Should the forms authentication cookie 
and ticket be reissued if they are about to expire?
-->