【问题标题】:Send an email when session expires会话到期时发送电子邮件
【发布时间】:2017-08-10 17:13:56
【问题描述】:

有一个 web 应用程序,其中 session 有 idletimeoout,2 小时。现在,当会话空闲 2 小时时,我需要发送一封电子邮件。如何在会话到期时引发事件?

services.AddSession(options =>
            {
                // Session timeout is at 2 hours
                options.IdleTimeout = TimeSpan.FromHours(2);
            }); /

【问题讨论】:

    标签: asp.net-mvc razor


    【解决方案1】:

    在您的 Global.asax.cs 文件中,您可以添加事件处理程序:

    protected void Session_End(object sender, EventArgs e)
    {
        // Send your email
    }
    

    请注意,您可能需要add something to the session to ensure that the end event is raised。您可以通过在创建会话时添加一个虚拟变量来确保发生这种情况:

    protected void Session_Start()
    {
        Session["SessionID"] = Session.SessionID;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-20
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 2015-03-20
      • 1970-01-01
      • 2013-12-24
      相关资源
      最近更新 更多