利用前端Ajax过段时间加载一次后台防止Session过期
$(function () {
function post() {
$.ajax({
type: "post",
contentType: "application/json",
url: "WebBlock.aspx"
})
}
setInterval(post,30000)
})
Width="449px">
runat="server" Text="保存" OnClientClick="" οnclick="Button1_Click" />
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没传过来时执行此语句 } } } }
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。