AJAX实现防止Session过期
利用前端Ajax过段时间加载一次后台防止Session过期 前台代码 <html xmlns="http://www.w3.org/1999/xhtml"> 后台代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; namespace WebApplication2 { public partial class WebBlock : System.Web.UI.Page { protected void Page_Load(object sender,EventArgs e) { } protected void Button1_Click(object sender,EventArgs e) { if (Session["user"] != null) { FileStream stream = File.Open(@"d:1.txt",FileMode.OpenOrCreate,FileAccess.Write);//向电脑中写入数据 StreamWriter writer = new StreamWriter(stream); writer.Write(TextBox1.Text); writer.Dispose(); stream.Dispose(); } else { Response.Redirect("Error.aspx");//当Session没传过来时执行此语句 } } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |