asp.net url重写有关问题
asp.net url重写问题
我采取的是HttpModule的方式进行重写
在本机(iis7.5)上,这种方式可以拦截后缀为html的网址,也可以拦截无后缀的网址
在办公室(iis5.1)的机器上,这种方式可以拦截后缀html的网址,但不可以拦截无后缀的网址
在服务器上(iis6.0)上,这种方式不可以拦截后缀为html的网址,只能拦截无后缀的网址
下面是代码
[code=xml]
<httpModules>
<add type="xinchen.Web.HttpModule" name="UrlRewriter" />
</httpModules>
[/code]
我想知道的是怎样才能在服务器上也就是iis6.0上拦截html后缀的网址,前提是我不能改变服务器上的任何东西,因为这是虚拟主机
------解决方案--------------------
不修改服務器設置不可能實現了!
------解决方案--------------------
以前用httphandler弄过。 都能拦截到。 不过httpmodule也是可以的。
要弄一下IIS。 有IIS版本,HTML这些申请时不会交给.net处理的。要自己设置。 忘记了。。
我采取的是HttpModule的方式进行重写
在本机(iis7.5)上,这种方式可以拦截后缀为html的网址,也可以拦截无后缀的网址
在办公室(iis5.1)的机器上,这种方式可以拦截后缀html的网址,但不可以拦截无后缀的网址
在服务器上(iis6.0)上,这种方式不可以拦截后缀为html的网址,只能拦截无后缀的网址
下面是代码
- C# code
public class HttpModule : IHttpModule { private HttpContext context; private string Root; private string Url; public void Dispose() { } public void Init(HttpApplication context) { this.context = context.Context; Root = this.context.Request.ApplicationPath; context.BeginRequest += new EventHandler(Application_BeginRequest); } private void Application_BeginRequest(object sender, EventArgs e) { context = sender.To<HttpApplication>().Context; Url = context.Request.Url.LocalPath.ToLower(); if (string.IsNullOrEmpty(Url.RegExReplace(Root+"/index", ""))) { context.RewritePath(Root+"/Index.aspx"); } } }
[code=xml]
<httpModules>
<add type="xinchen.Web.HttpModule" name="UrlRewriter" />
</httpModules>
[/code]
我想知道的是怎样才能在服务器上也就是iis6.0上拦截html后缀的网址,前提是我不能改变服务器上的任何东西,因为这是虚拟主机
------解决方案--------------------
不修改服務器設置不可能實現了!
------解决方案--------------------
以前用httphandler弄过。 都能拦截到。 不过httpmodule也是可以的。
要弄一下IIS。 有IIS版本,HTML这些申请时不会交给.net处理的。要自己设置。 忘记了。。