asp.net URLRewriter url重写本机怎么配置
只是配置web.config 吗  ?还要不要写什么代代码呀 这个我web.config里面配置的 看哈有错没的  反正运行就是出不来
  <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>
<RewriterConfig>
    <Rules>
      <RewriterRule>
        <LookFor>~/r_(.[\d]*).html</LookFor>
        <SendTo>~/logs.aspx?id=$1</SendTo>
      </RewriterRule>
    </Rules>
  </RewriterConfig>
<httpHandlers>
      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
    </httpHandlers>大虾们帮帮忙呀  本机运行不行呢 

解决方案 »

  1.   

    我改写了URLRewriter的DLL因为我的需求是要域名重写。
    我的web.config配置是<configSections>
       <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
    </configSections>
    <RewriterConfig>
    <Rules>
    <RewriterRule>
    <LookFor>http://(\d+)\.xxx\.xxx\.cn/default\.aspx</LookFor>
    <SendTo>~/gonggao/ggview.aspx?ggid=$1</SendTo>
    </RewriterRule>
    </Rules>
    </RewriterConfig>
    <httpHandlers>
          <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
    </httpHandlers>主要重写了RewriterFactoryHandler.cs里面的下面的内容来实现的,你可以把重写域名的注释掉,把重写url的启用 然后编译在引用试试看。/// <summary>
            /// GetHandler is executed by the ASP.NET pipeline after the associated HttpModules have run.  The job of
            /// GetHandler is to return an instance of an HttpHandler that can process the page.
            /// </summary>
            /// <param name="context">The HttpContext for this request.</param>
            /// <param name="requestType">The HTTP data transfer method (<b>GET</b> or <b>POST</b>)</param>
            /// <param name="url">The RawUrl of the requested resource.</param>
            /// <param name="pathTranslated">The physical path to the requested resource.</param>
            /// <returns>An instance that implements IHttpHandler; specifically, an HttpHandler instance returned
            /// by the <b>PageParser</b> class, which is the same class that the default ASP.NET PageHandlerFactory delegates
            /// to.</returns>
            public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
            {
                context.Trace.Write("RewriterFactoryHandler", "Entering RewriterFactoryHandler");
                //string sendToUrl = url;url重写
                string sendToUrl = context.Request.Url.AbsolutePath;//域名重写            string filePath = pathTranslated;
                // get the configuration rules
                RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;
                // iterate through the rules
                for (int i = 0; i < rules.Count; i++)
                {
                    // Get the pattern to look for (and resolve its URL)
                    string lookFor = "^" + RewriterUtils.ResolveUrl(context.Request.ApplicationPath, rules[i].LookFor) + "$";                // Create a regular expression object that ignores case...
                    Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);                // Check to see if we've found a match
                    //if (re.IsMatch(url))//URL重写
                    if (re.IsMatch(context.Request.Url.AbsolutePath))//域名重写
                    {
                        // do any replacement needed
                        //sendToUrl = RewriterUtils.ResolveUrl(context.Request.ApplicationPath, re.Replace(url, rules[i].SendTo));//url重写
                        sendToUrl = RewriterUtils.ResolveUrl(context.Request.ApplicationPath, re.Replace(context.Request.Url.AbsolutePath, rules[i].SendTo));//域名重写                    // log info to the Trace object...
                        context.Trace.Write("RewriterFactoryHandler", "Found match, rewriting to " + sendToUrl);                    // Rewrite the path, getting the querystring-less url and the physical file path
                        string sendToUrlLessQString;
                        RewriterUtils.RewriteUrl(context, sendToUrl, out sendToUrlLessQString, out filePath);                    // return a compiled version of the page
                        context.Trace.Write("RewriterFactoryHandler", "Exiting RewriterFactoryHandler"); // log info to the Trace object...
                        return PageParser.GetCompiledPageInstance(sendToUrlLessQString, filePath, context);
                    }
                }
                // if we reached this point, we didn't find a rewrite match
                context.Trace.Write("RewriterFactoryHandler", "Exiting RewriterFactoryHandler"); // log info to the Trace object...
                return PageParser.GetCompiledPageInstance(url, filePath, context);
            }
      

  2.   

    iis配置方法:IIS配置:网站->属性->目录->配置(G)...->映射->应用程序扩展->添加
    可执行文件:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
    扩展名:.html
    动作:限制为 GET,HEAD,POST,DEBUG
    脚本引擎:选中
    确认文件是否存在:不选
      

  3.   


    RewriterFactoryHandler.cs 这个类在那呢?
      

  4.   

    你留个邮箱吧 我把整个的Rewriter的类都发给你(微软的,开源的)
      

  5.   


    [email protected]  谢谢哈
      

  6.   

    今天上午刚弄了,添加section<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
    在HttpModels这个地方添加上<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
    定义规则<RewriterRule>
            <LookFor>~/Shop/(\d+)</LookFor>
            <SendTo>~/Shop/default.aspx?SId=$1</SendTo>
          </RewriterRule>
    然后你在页面写链接的时候~/shop/3他就解释到了~/shop/default.aspx?SId=3
      

  7.   

    如果在VS中调度通过后,然后发布后需要在iis里添加映射就可以了如4楼说得就行了
      

  8.   

    <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
    这个里面没有name属性吧
      

  9.   


    能不能也发一个给我哦 谢谢啦  [email protected]