郁闷,这个问题一直困扰着我。楼上的兄弟,就是URL重写呀。没有代码的,只是配置一下而已。难道大家都没有用过URL重写吗?

解决方案 »

  1.   

    楼上兄弟,我看了。确实没有判断是否为NULL的。该如何解决?难道可以去掉吗? protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
    {
    // log information to the Trace object.
    app.Context.Trace.Write("ModuleRewriter", "Entering ModuleRewriter"); // get the configuration rules
    RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules; // iterate through each rule...
    for(int i = 0; i < rules.Count; i++)
    {
    // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
    string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$"; // Create a regex (note that IgnoreCase is set...)
    Regex re = new Regex(lookFor, RegexOptions.IgnoreCase); // See if a match is found
    if (re.IsMatch(requestedPath))
    {
    // match found - do any replacement needed
    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo)); // log rewriting information to the Trace object
    app.Context.Trace.Write("ModuleRewriter", "Rewriting URL to " + sendToUrl); // Rewrite the URL
    RewriterUtils.RewriteUrl(app.Context, sendToUrl);
    break; // exit the for loop
    }
    } // Log information to the Trace object
    app.Context.Trace.Write("ModuleRewriter", "Exiting ModuleRewriter");
    }
      

  2.   

    有人说是因为缓存失效引起的。请问大家,如何不让缓存失效?在web.config里面可以配置吗?
      

  3.   

    根本就不用自己写程序,把微软那个下载下来,应用一下,再调整一下WEB.CONFIG就可以用了
      

  4.   

    <RewriterConfig>
        <Rules>
          <RewriterRule>
            <LookFor>~/BBS/(\d+)/(\d+)\.html</LookFor>
            <SendTo>~/BBS/BrowsePost.aspx?smallid=$1&amp;postid=$2</SendTo>
          </RewriterRule>
          
          <RewriterRule>
            <LookFor>~/BBS/(\d+)\.html</LookFor>
            <SendTo>~/BBS/PostList.aspx?smallid=$1</SendTo>
          </RewriterRule>
          <RewriterRule>
            <LookFor>~/BBS/SendPost-(\d+)\.html</LookFor>
            <SendTo>~/BBS/SendPost.aspx?smallid=$1</SendTo>
          </RewriterRule>
        <RewriterRule>
            <LookFor>~/articles/(\d+)\.html</LookFor>
            <SendTo>~/site_browsearticle.aspx?articleid=$1</SendTo>
          </RewriterRule>
          <RewriterRule>
            <LookFor>~/doctors/(\d+)\.html</LookFor>
            <SendTo>~/site_browsedoctor.aspx?doctorid=$1</SendTo>
          </RewriterRule>
        </Rules>
      </RewriterConfig><httpModules>
          <add name="ScriptModule" type="Microsoft.Web.Services.ScriptModule"/>
          <add name="BridgeModule" type="Microsoft.Web.Services.BridgeModule"/>
          <add name="WebResourceCompression" type="Microsoft.Web.Services.WebResourceCompressionModule"/>
          <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
        </httpModules>
      

  5.   

    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
      

  6.   

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
    </configSections>
    <connectionStrings>这个有用嘛?
      

  7.   

    这样看不出问题,如果不是自己写的url重写dll,用别人的话,错误很常见