本文介绍了如何避免在web.config中的会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在asp.net web配置文件写什么,这样我的会议时间被延长了。并请告诉我具体位置我应该在哪里放置code在网络配置

What should I write in web config file in asp.net so that my session time is extended. and please tell me the exact location where should I place the code in web config

推荐答案

如果你想阻止timeing所有的时间会话可以做到这一点,而不是增加会话超时。

If you are trying to stop the session from timeing out all the time you can do this rather than increasing the session timeout.

KeepAlive.aspx

KeepAlive.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KeepAlive.aspx.cs" Inherits="Pages.KeepAlive" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ OutputCache Location="None" VaryByParam="None" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    KEEP ALIVE
    </div>
    </form>
</body>
</html>

请Alive.aspx.cs

Keep Alive.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Pages
{
    /// <summary>
    /// Page to keep the session alive
    /// </summary>
    public partial class KeepAlive : System.Web.UI.Page
    {
        //- EVENTS ------------------------------------------------------------------------------------------------------------------

        #region Events

        /// <summary>
        /// Page Load
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">args</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Add refresh header to refresh the page 60 seconds before session timeout
                Response.AddHeader("Refresh", Convert.ToString((Session.Timeout * 60) - 60));
            }
            catch (Exception)
            {
                throw;
            }
        }

        #endregion Events

        //---------------------------------------------------------------------------------------------------------------------------
    }
}

然后在你的母版页创建刷新保持会话活着的iFrame

Then in your master page create an iFrame that refreshes to keep the session alive

<iframe id="Defib" src="KeepAlive.aspx" frameborder="0" width="0" height="0" runat="server">
</iframe>

这篇关于如何避免在web.config中的会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:05