ASP.NET防后退
如有页面Admin,则在其cs文件中写如下代码:
protected void Page_Load(object sender, EventArgs e)
{
Response.AddHeader("Cache-Control", "no-cache");
Response.Expires = -1;
Response.Cache.SetNoStore();
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Last-Modified", DateTime.Now.ToString() + " GMT");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (Session["AdminNumber"] == null)
{
Response.Redirect("~/Login.aspx");
}
}
在Login页的cs文件中写如下代码:
protected void Page_Load(object sender, EventArgs e)
{
Response.AddHeader("Cache-Control", "no-cache");
Response.Expires = -1;
Response.Cache.SetNoStore();
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Last-Modified", DateTime.Now.ToString() + " GMT");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!IsPostBack)
{
Session.Clear();
}
}
如此便可轻松拒绝页面的回退!
相关文档:
/// <summary>
/// 根据指定参数返回BitMap对象
/// 引用如下:
/// using System.Drawing;
/// 调用例子如下:
......
HttpContext.Current.Request.Url.ToString() 并不可靠。
如果当前URL为
http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=¼&fra ......
方法
数据量
生命期
作用域
位置
Application
任意大小
整个应用程序
所有用户
服务端
Cache
任意大小
根据需要设定
所有用户
服务端
Cookie
简单数据
根据需要设定
单个用户
客户端
Session
简单数据
用户活动时间+延迟时间(20分钟)
单个用户
服务端
Web.Config
极少改变简单数据
直到改变配 ......
+++ HiddenField01.aspx页面
++ 页面代码如下:
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:HiddenField ID="HiddenField2" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
++ 后台代码,如下:
protected void Button1_C ......
+++ 修改WebConfig文件:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="connStr" value="Data Source=ora11g;uid=scott;pwd=tiger;unicode=true"/>
</appSettings>
<connectionStrings>
<ad ......