【问题标题】:Different auto-redirects for different pages on timeout超时时不同页面的不同自动重定向
【发布时间】:2016-02-09 15:04:23
【问题描述】:

我们使用超时和自动直接,它们运行良好。我只是想知道是否可以在不更改配置文件的情况下更改自动重定向页面。

例如,当我在页面 X 时,我希望它在超时发生时自动重定向到页面 Y。对于所有其他页面,这将是通常的登录页面重定向。

【问题讨论】:

  • 你的意思是在内部调用数据库之类的东西时超时吗?
  • 对不起,你是对的,我在那里有点含糊。我的意思是会话超时。

标签: c# webforms timeout


【解决方案1】:

StackOverflow 中有多篇文章甚至线程解释了超时重定向。

应该回答您的问题的一个特别是:

Redirect to login page after session timeout

在此答案中,它重定向到 Login.aspx,但您可以签入您感兴趣的页面并直接转到另一个页面。

这是响应中显示的代码:

protected void Page_Init(object sender, EventArgs e)
{
    if (Context.Session != null)
    {
        if (Session.IsNewSession)
        {
            HttpCookie newSessionIdCookie = Request.Cookies["ASP.NET_SessionId"];
            if (newSessionIdCookie != null)
            {
                string newSessionIdCookieValue = newSessionIdCookie.Value;
                if (newSessionIdCookieValue != string.Empty)
                {
                    // This means Session was timed Out and New Session was started
                    Response.Redirect("Login.aspx");
                }
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 2020-02-20
    • 2015-10-22
    • 2020-09-20
    • 2010-10-22
    相关资源
    最近更新 更多