关于Httpmodule

songq 2009-04-09 10:26:20
基于IIS5.
我想实现在httpmodules中能够处理.htm的静态页面请求,不知如何来做?
我现在的做法是:
1. 已经在IIS5中将.htm映射到aspnet_isapi.dll,并且check that file existing 也uncheck了
2. web.config中也已经配置好了我的httpmodule实现类
但是http://localhost/WebApp/test.htm还是出错404,不能找到该文件。
而http://localhost/WebApp/test.aspx执行并显示httpmodule里的输出。

弄了好几天了没有搞定,请不吝赐教,多谢多谢。
...全文
134 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
songq 2009-04-11
  • 打赏
  • 举报
回复
TO zzxap,wuyq11: 我该配置的都配置了,代码也写了,为什么没有在htm内容输出前后插入我在module里边要加入的内容呢?
songq 2009-04-11
  • 打赏
  • 举报
回复
To ojekleen:
现在可以显示test.htm里边的内容了,但是在Application_BeginRequest方法里边的插入内容还是没有显示,该配置的都已经像上边那样配置了。 还请指教,下边就是我的特别简单的Httpmodule实现代码。

using System;
using System.Web;
public class HelloWorldModule : IHttpModule
{
public HelloWorldModule()
{
}

public String ModuleName
{
get { return "HelloWorldModule"; }
}

// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application)
{
application.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
application.EndRequest +=
(new EventHandler(this.Application_EndRequest));
}

private void Application_BeginRequest(Object source,
EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string filePath = context.Request.FilePath;
string fileExtension = VirtualPathUtility.GetExtension(filePath);
//if (fileExtension.Equals(".aspx"))
{
context.Response.Write("" +
"HelloWorldModule: Beginning of Request" +
"<hr>");
}
}

private void Application_EndRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string filePath = context.Request.FilePath;
string fileExtension = VirtualPathUtility.GetExtension(filePath);
//if (fileExtension.Equals(".aspx"))
{
context.Response.Write("" +
"HelloWorldModule: End of Request");
}
}
public void Dispose()
{
}
}
zzxap 2009-04-09
  • 打赏
  • 举报
回复
http://blog.csdn.net/ceocio/archive/2004/08/13/74090.aspx

http://www.lastknight.com/DotNet-Url-Rewriting-and-Caching-Engine.aspx
zzxap 2009-04-09
  • 打赏
  • 举报
回复
1. you need to map html to aspnet_isapi.dll in IIS, so that ASP.NET engine will handle html files, otherwise, you need to write ISAPI dll and do the url rewrite yourself, for example, see

2. you just need to modify the regular expression in RewriterRule in the configuation file, for example


<RewriterRule>
<LookFor>~/(\d+)/(\d+)\.html?</LookFor>
<SendTo>~/a.aspx?b=$1&c=$2</SendTo>
</RewriterRule>

also see
URL Rewriting with ASP.NET
http://www.codeproject.com/aspnet/urlrewriter.asp
ojekleen 2009-04-09
  • 打赏
  • 举报
回复
htm默认为不进ASP.net管道的。。。

如果你在管道做了处理,应该是在request_begin事件中可以得到请求的URL。

具体为什么找不到文件,会不会是你的路径问题?
hmily821023 2009-04-09
  • 打赏
  • 举报
回复
我发的怎么没了?
晕 啥玩意啊 ?
ws_hgo 2009-04-09
  • 打赏
  • 举报
回复
如梦兄
总能找到很好的答案
佩服
wuyq11 2009-04-09
  • 打赏
  • 举报
回复
通过伪静态方式实现
参考
参考

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧