实现IHttpModule接口,给每个页面输出一段脚本
在App_Code文件中添加TGModule.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts; /// <summary>
///TGModule 的摘要说明
/// </summary>
public class TGModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
HttpRequest request = application.Request;
HttpResponse response = application.Response; string uri = request.RawUrl; string a = uri.Substring(uri.LastIndexOf(".") + 1); //只拦截aspx html页面
if (a.Contains("aspx") || a.Contains("html"))
{
context.Response.Write(@"<script type='text/javascript' src='/zhuanti/tuangou.js'></script>");
}
}
}
在web.config中配置
<httpModules>
<add name="TGModule" type="TGModule"/> </httpModules>
完成!这样在每个页面的末尾就自动添加了一段脚本 而不会影响到css js文件
<script type='text/javascript' src='/zhuanti/tuangou.js'></script>
如图:虽然在html标签外部 但是还是可以运行的。

关于IhttpModule详细介绍可以看这里:http://www.cnblogs.com/chenlulouis/archive/2009/12/18/1626918.html
实现IHttpModule接口,给每个页面输出一段脚本的更多相关文章
- .net实现IHttpModule接口顾虑器
这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#使用IHtt ...
- tp5页面输出时,搜索后跳转下一页的处理
tp5页面输出时,搜索功能在跳转下一页时,如果不做任何处理,会返回原有是第二页输出的数据.为了保证跳转下一页时输出的是搜索到的数据,做以下处理. (要根据自己的搜索字段进行适当修改) 页面js代码,给 ...
- js引入php 用来加载静态页面 输出到页面中
HTML页面中加入代码 <script type="text/javascript" src="http://www.域名.com/js.php?id=tjyd&q ...
- original.txt和提交的页面输出的文字的混合文件
如果从准确的角度来说,那PHP文档是最准确的,因为它很简练的列出了实现文本类文件触发下载所需要的三条语句,以PDF为例就是: 代码如下:// We'll be outputting a PDF hea ...
- ASP.NET缓存全解析2:页面输出缓存 转自网络原文作者李天平
页面输出缓存是最为简单的缓存机制,该机制将整个ASP.NET页面内容保存在服务器内存中.当用户请求该页面时,系统从内存中输出相关数据,直到缓存数据过期.在这个过程中,缓存内容直接发送给用户,而不必再次 ...
- httl开源JAVA模板引擎,动态HTML页面输出
HTTL(Hyper-Text Template Language)是一个适用于HTML输出的开源JAVA模板引擎,适用于动态HTML页面输出,可用于替代JSP页面,它的指令类似于Velocity. ...
- 把aspx页面输出成xml的方法注意事项
先贴代码 Response.Charset = "gb2312"; Response.ContentType = "text/xml"; Response.Co ...
- 使用c#反射实现接口可视化调试页面
直接上代码,引用CommTools.dll.包括aspx显示页面和aspx.cs获取反射数据源代码 using System; using System.Collections.Generic; us ...
- JAVA-JSP内置对象之out对象进行页面输出
相关资料:<21天学通Java Web开发> out对象 out对象进行页面输出1.通过out对象的print()方法和println()方法进行页而输出.2.不同的println()方法 ...
随机推荐
- ylbtech-Unitity-CS:Indexers
ylbtech-Unitity-CS:Indexers 1.A,效果图返回顶部 1.B,源代码返回顶部 1.B.1, // indexer.cs // 参数:indexer.txt using S ...
- 你应该知道的jQuery技巧
帮助提高你jQuery应用的简单小技巧. 回到顶部按钮 图片预加载 判断图片是否加载完 自动修补破损图像 Hover切换class类 禁用输入 停止正在加载的链接 toggle fade/slide ...
- android之location02
package com.example.mars_3300_location02; import java.net.ContentHandler; import java.util.List; imp ...
- python 最长公共子序列
网上有很多,但有bug,特别是这个:http://www.oschina.net/code/snippet_16840_2015 好大的坑... get length def lcs_len(a,b) ...
- 线程中的wait() 与 锁的关系
我们先看一段代码: /** * 计算输出其他线程锁计算的数据 * */ public class ThreadA { public static void main(String[] args) th ...
- 20145305 《Java程序设计》第10周学习总结
学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的数据,这个就是狭义的网络编程范畴.在发送和接收数据时, ...
- 20145305 《Java程序设计》第9周学习总结
教材学习内容总结 1.厂商在操作JDBC驱动程序时,依方式可将驱动程序分为4种类型: JDBC-ODBC Bridge Driver Native API Driver JDBC-Net Driver ...
- VB6的命令行参数
在DOS窗口下执行如下命令: C:\Program Files\Microsoft Visual Studio\VB98>vb6 /?
- (medium)LeetCode 230.Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
- 20. Valid Parentheses(stack)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...