如何查找会话是否有效? [英] How to find session is working or not ?
本文介绍了如何查找会话是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace seesion
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["username"] = TextBox1.Text;
Session["password"] = TextBox2.Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}
}
}
我尝试了什么:
显然,正确的输出应该是这样的:
欢迎aany
yoursession id是:sqsvwn3wn1fxc2vig0vk5wc
sessioncount:2
会话超时值是20
但是没有进入重定向页面webFrom2 .aspx在那个webForm.aspx中只有4个标签打印在crt输出上面。
请给frds提供crt代码来解决这个问题
What I have tried:
obviously, the correct output should come like this:
" welcome aany
yoursession id is:sqsvwn3wn1fxc2vig0vk5wc
sessioncount:2
session timeout value is 20"
but does not come in redirect page "webFrom2.aspx" in that webForm.aspx there only 4 label to print above crt output.
pls frds give crt code for this problem
推荐答案
请参考您的代码并更正它。
WebForm2 ASPX
Refer this with your code and correct it.
WebForm2 ASPX
<div>
<asp:Label ID="lblInfo" runat="server"></asp:Label> <br />
<asp:Label ID="lblSession" runat="server"></asp:Label><br />
<asp:Label ID="lblSessionCount" runat="server"></asp:Label><br />
<asp:Label ID="lblSessionTimeOut" runat="server"></asp:Label><br />
</div>
WebForm2代码背后 CS
WebForm2 Code Behind CS
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
lblInfo.Text = string.Format("Welcome {0}", Session["username"]);
lblSession.Text = string.Format("Your Session Id is {0}", Session.SessionID);
lblSessionCount.Text = string.Format("sessioncount : {0}", Session.Count);
lblSessionTimeOut.Text = string.Format("session timeout value is {0}", Session.Timeout);
}
}
}
这篇关于如何查找会话是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文