using System;
using System.Web;
using System.Collections;namespace HttpURLModule
{
    public class HttpReWriter : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(contextRequest);
        }        private void contextRequest(object sender, EventArgs e)
        {
            /*
            www.rbmm.cn/rbxx/Index.html创建单位主页
            www.rbmm.cn/rbxx/zzld_Index.html?id=1创建单位栏位主页
            www.rbmm.cn/rbxx/zzld_201201_2.html内容
            BuildHtml/100006002/Index.html
            */
            HttpApplication app = sender as HttpApplication;
            Hashtable DktUrl = app.Application["DKTUrl"] as Hashtable;
            if (app == null) return;            string currentUrl = app.Context.Request.RawUrl.TrimEnd('/');
            string[] slUrl = currentUrl.Split('/');
            string newUrl = currentUrl;
            if (slUrl.Length == 2)
            {
                object objValue = DktUrl[slUrl[1].ToLower()];
                if (objValue != null)
                {
                    newUrl = slUrl[0] + "/BuildHtml/" + (string)objValue + "/Index.html";
                }
            }
            else if (slUrl.Length > 2)
            {
                object objValue = DktUrl[slUrl[1].ToLower()];
                if (objValue != null)
                {
                    newUrl = currentUrl.Replace("/" + slUrl[1] + "/", "/BuildHtml/" + (string)objValue + "/");
                }
            }
            app.Context.RewritePath(newUrl);
        }        public void Dispose() { }
    }
}这是我写的URL重写的代码比如我输入:www.rbmm.cn/renben/index.aspx  需要解析成:www.rbmm.cn/BuildHtml/100006002/index.aspx  而实际没有目录:renben ,系统提示404错误。
我怎么做的没有 renben目录 解析到BuildHtml/100006002目录

解决方案 »

  1.   

    另外在VS运行模式 没有问题,只有在部署IIS上会报404错误
      

  2.   

    推荐楼主看一下:
    http://www.cnblogs.com/luckdv/articles/1687942.html
    希望对你有帮助
      

  3.   

    没那个路径,估计newUrl,有问题,iis上的网站目录与调试目录是不一样的,看下另外,你rewrite,用这个有点复杂了,而且,你没用正则,灵活性太差,匹配的逻辑修改,要重编译,麻烦推荐直接webconfig配置的,直观,灵活
      

  4.   

    URL重写 用正则
    具体我也不是很懂.
      

  5.   

    http://blog.csdn.net/zhoufoxcn/article/details/4346356
    http://www.iteye.com/wiki/blog/460681