发布:2021/11/26 16:56:04作者:管理员 来源:本站 浏览次数:863
在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>
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4