session的使用
来源:互联网 发布:oracle性能监控软件 编辑:程序博客网 时间:2024/06/16 18:55
Session、Cookie、Application的问题:
application.cache是全局的,所有用户在所有页面都可以访问
session是用户级别的对象,同一个用户在所有页面都可以访问
viewstate是页面级别的对象,同一个用户只能在同一个页面访问
实现一个简单的登录页面:
登录页:aspx页面
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
用户名
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
密码
</td>
<td>
<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="登录" onclick="Button1_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
aspx.cs页面
protected void Button1_Click(object sender, EventArgs e)
{
if (txtUserName.Text == "admin" && txtPwd.Text == "888888")
{
Session["user"] = txtUserName.Text;
Response.Redirect("WebIndex.aspx");
}
}
主页的aspx页面
<script src="js/Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
function post() {
$.ajax({
type:"post",
contentType:"application/json",
url: "WebIndex.aspx"
})
}
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Height="411px" TextMode="MultiLine" Width="529px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="写入" />
</div>
</form>
</body>
主页的aspx.cs页面
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["user"] != null)
{
FileStream stream = File.Open(@"d:\1.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter write = new StreamWriter(stream);
write.Write(TextBox1.Text);
write.Dispose();
stream.Dispose();
}
else
{
Response.Redirect("Error.aspx");
}
}
错误页的aspx页面
<body>
<form id="form1" runat="server">
<div>
由于您长时间没有登录,页面已注销,请重新登录!
</div>
</form>
</body>
- 使用flex 的session
- hibernate Session的使用
- SESSION 的使用
- Session使用的方法
- session的使用原则
- session的使用
- servlet session的使用
- Session的使用
- 使用session的原则
- session的使用详解
- Struts2 -- session的使用
- session 的使用
- Struts2 -- session的使用
- Session 对象的使用
- session.flush()的使用
- session的使用
- Session的使用技巧
- session.flush()的使用
- Linux下使用USB转串口读取GPS数据
- 关于windows的MessageBox
- Dropbox CEO MIT毕业典礼演讲:冒险精彩人生--转载
- HTML5实现坦克乱走还能发出一个子弹
- HDU4506(快速幂)
- session的使用
- 诺基亚Lumia920竞争力分析——对比三星Ativ S、Galaxy S3、HTC One X、Iphone5
- 谈恋爱谈何容易
- 散谈游戏保护那点事~就从_TP开始入手吧
- Objective-C中的@property和@synthesize用法
- 上下左右箭头的ASCII值
- 云存储的结构模型
- 第三方应用分享到微信朋友圈功能
- WIN7系统设置WIFI热点