今天发现一个好奇怪的现象,原来一直没有注意,今天程序出了问题后才发现问题的严重性。
我在一个小项目中用到 HttpModule
public class HttpModule : System.Web.IHttpModule
{
/// <summary>
/// 实现接口的Init方法
/// </summary>
/// <param name="context"></param>
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(ReUrl_BeginRequest);
}
/// <summary>
/// 重写Url
/// </summary>
/// <param name="sender">事件的源</param>
/// <param name="e">包含事件数据的 EventArgs</param>
private void ReUrl_BeginRequest(object sender, EventArgs e)
{
......
HttpContext context = ((HttpApplication)sender).Context;
string requestPath = context.Request.Path.ToLower();
}
}
程序启动,在Login.aspx 开始调用的问题,发现一个这样的问题:
login.aspx会多次调用这个ReUrl_BeginRequest 方法,因为我跟踪的时候,发现
requestPath = login.aspx
styles/dntmanager.css
JScript/common.js
images/login-top.gif
..
TMD好奇怪。为什么这些图片css文件也会调用一次这个HttpModule中的beginRequest方法呢?
我的Login.aspx文件是这样的:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="GPRPWeb.aspx.login" %>
<%@ Register TagPrefix="cc1" Namespace="GPRP.GPRPControls" Assembly="GPRPControls" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>登录</title>
<link href="../styles/dntmanager.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../JScript/common.js"></script>
<script type="text/javascript">
if(top.location!=self.location)
{
top.location.href = "aspx/login.aspx";
}
</script>
</head>
<body style="background:#f4f6f7;">
<form id="Form1" method="post" runat="server">
<div id="LoginBar">
<ul>
<span class="td1">
<asp:literal id="Msg" runat="server"></asp:literal>
<br />
<br />
</span>
<li class="LoginTop"><img src="../images/login-top.gif" alt=""/></li>
<li class="FormNav">
<dl>
<dt><label><asp:literal id="lblUserName" runat="server"></asp:literal></label><cc1:textbox id="UserName" runat="server" RequiredFieldType="暂无校验" Text="" size="25" ></cc1:textbox></dt>
<dd><label><asp:literal id="lblPwd" runat="server"></asp:literal></label><cc1:textbox id="PassWord" runat="server" RequiredFieldType="暂无校验" Text="" TextMode="Password" size="20" ></cc1:textbox>
<dd><label><asp:literal id="lblLanguage" runat="server"></asp:literal></label><cc1:DropDownList ID="dplLanguage" runat="server">
</cc1:DropDownList>
<dd><input id="login" type="submit" value="<%=submit%>" style="color:white;font-weight:bold;width:60px; height:26px; border:0; background:url(../images/button.gif) no-repeat left top; cursor:pointer; margin-left:65px;"></dd>
</dl>
</li>
<li><img src="../images/login-bottom.gif" alt=""/></li>
</ul>
</div>
</form>
<div id="copyright"><%=footer%></div>
</body>
</html>
各位同行兄弟,请问我怎么解决,一个页只调用一次这个httpMoudle呢?