您的位置:首页 > 其它

IIS内核模式缓存导致串号问题

2014-03-29 15:40 357 查看
最近系统遇到一个很不可思议的问题,在使用过程中出现界面显示的名字不是用户自己的名字,而是变成另一个人的名字,出现了串号现象。经过不断的调试追踪,终于找出了问题症结所在,就是配置了IIS内核模式缓存。为了说明问题,写了两个测试页面:

第一个页面:Default.aspx模拟用户登录

前端部分:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCache.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>登录</title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server" Text="确定" onclick="Button1_Click" />
</div>
</form>
<p>
IIS-输出缓存-添加:</p>
<p>
文件扩展名 .aspx</p>
<p>
内核模式缓存</p>
<p>
文件缓存监视 使用文件更改通知</p>
</body>
</html>
后端部分:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestCache
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
Session["UserInfo"] = TextBox1.Text;
Response.Redirect("WebForm1.aspx");
}
}
}


第二页面:展示用户名

前端部分

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestCache.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>显示名称</title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<asp:Label ID="lbUserName" runat="server" ></asp:Label>
</div>
<div>
<%=Request.UserAgent %>
</div>
<div>不断的刷新我!记得要不同浏览器哦!</div>
</form>
</body>
</html>


后端部分:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestCache
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username= Session["UserInfo"] as string;
if(string.IsNullOrEmpty(username)) Response.Redirect("Default.aspx");
lbUserName.Text = username;

}
}
}


配置IIS内核模式缓存

1.打开IIS选择输出缓存



2.配置输出缓存加上,文件扩展名.aspx,勾选内核模式缓存,使用文件更改通知



3.配置结果如下



用户chrome和IE分别打开Default.aspx页面



IE用User1登录,chrome用user2登录:



不断刷新两个浏览器



会发现IE也变成user2,这就是看到用户串号的结果。

输出缓存是会保留页面的副本,不会执行页面的代码的。为了保持正确,如果设置了内核模式缓存可以在页面url加上请求参数来区别,如



如果使用了用户模式缓存,则要在高级设置里面加上请求参数如:



结语:

在IIS设置输出缓存得注意了,这个是对全局有效的,如果页面显示的内容跟使用用户权限有关的,那么可能导致整个系统不可以用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: