使用HttpModule(给页面添加页头和页尾,重写URL)
来源:互联网 发布:一个都不能少影评知么 编辑:程序博客网 时间:2024/05/17 03:17
使用HttpModule(给页面添加页头和页尾)
Module.cs
#region IHttpModule 成员
public void Dispose() { }
public void Init(HttpApplication context)
{
context.BeginRequest +=new EventHandler(context_BeginRequest);
context.EndRequest +=new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
((HttpApplication)sender).Response.Output.Write("<hr>页尾");
}
void context_BeginRequest(object sender, EventArgs e)
{
((HttpApplication)sender).Response.Output.Write("页头<hr>");
}
#endregion
URL重写
public class UrlRewriter:IHttpModule{
public UrlRewriter()
{
// //TODO: 在此处添加构造函数逻辑 //
}
#region IHttpModule 成员
public void Dispose()
{ }
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
string requestPath = context.Request.Path.ToLower();
//判断请求路径是否为购买页面
if (requestPath.Contains("/httpmodule/goumai/"))
{
//找到路径中最后一个"/"的位置
int start = requestPath.LastIndexOf("/");
//找到最后一个"."的位置
int end = requestPath.LastIndexOf(".");
string id = requestPath.Substring(start + 1, (end - start));
context.RewritePath("~/goumai/goumai.aspx?id=" + id);
}
}
#endregion
}
Web.config
<configuration>
<system.web>
<httpModules>
<add name="Text" type="Module"/>
<!--<add name="UrlRewriter" type="UrlRewriter"/>-->
</httpModules>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
- 使用HttpModule(给页面添加页头和页尾,重写URL)
- 使用HttpModule实现URL重写
- URL重写 HttpModule进阶和dll重写
- HttpModule类(URL重写)
- HttpModule实现URL重写
- 使用 HttpModule 执行 URL 重写的时机选择
- DNN-HttpModule.UrlRewrite( url重写 )
- 利用HttpModule实现URL重写
- URL重写之在IIS7中使用HttpModule,在IIS5和IIS6中使用 ISAPIRewrite实现无扩展名的URL重写(节选自福娃儿)
- 给ListView添加头和尾
- HttpModule(URL重写).html伪静态
- ASP.NET HttpModule URL 重写 (一)
- iOS 给UIWebView添加头视图和尾视图
- .net通过继承HttpModule类实现Url重写
- IIS8如何安装和使用URL重写工具-URL Rewrite
- Vue2.0 给Tab标签页和页面切换过渡添加样式
- asp.net 页面url重写
- 使用url rewrite重写
- Linux c 目录操作函数scandir
- 程序员面试什么最重要?
- 科目四的题目你让我情何以堪
- 省市选择器
- TEST
- 使用HttpModule(给页面添加页头和页尾,重写URL)
- 如何成为编程高手?(高手秘笈)
- menuconfig过程详解
- mysql带输出参数存储过程(备忘)
- 今日心得
- Camera编程
- 实现新闻信息的修改和添加功能
- 求数组的主要元素
- 黑马程序员_html基础