Friday, April 15, 2011

URL Rewriter.NET web.config node issue

I'm using URL Rewriter.NET (which I'm liking a lot, by comparison to URL Rewriting.NET - more versitile it seems, don't get me wrong, I like URL Rewriting.NET, but it didn't seem to satisfy the need, given what I know of the tool). I'm trying to use the default-documents node to redefine the default documents for the site. I've tried adding it to the rewriter node, but I get a web.config error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: The element 'default-documents' is not allowed.

Source Error: 


Line 187:
Line 188:   <rewriter>
Line 189:    <default-documents>
Line 190:     <document>default.aspx</document>
Line 191:     <document>index.aspx</document>

Has anyone used this tool in the past, and does anyone know where to put this node (or proper usage)?

EDIT:

I tried the suggestion below, but it didn't seem to work quite right. Here is what is in my extra config file (this is the only contents in the config file)

<rewriter>
     <rewrite url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$" to="$1" processing="stop" />
     <default-documents>
      <document>default.aspx</document>
      <document>index.aspx</document>
     </default-documents>
</rewriter>
From stackoverflow
  • I've used urlrewriter before, and had some problems with actually setting a default document as well. However, eventually we got it (and other minor annoyances) to work by moving the urlrewriter config to different config file than web.config.

    <rewriter configSource="urlrewriter.config"/>
    

    Remember that you also have to disable default documents in IIS for the urlrewriter to work correctly. That caused a bunch of annoying problems as well.

    EDIT: Don't forget to add this line to your config sections in web.config

    <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
    

    Hope this helps.

    MasterMax1313 : I'll give this a shot, thanks!
    MasterMax1313 : adding it to a separate config file didn't resolve the issue.
  • This snippet works for me:

        <configSections>
            <section name="rewriter" 
                     requirePermission="false" 
                     type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" 
            />
        </configSections>
    
        <rewriter>
            <default-documents>
                <document>index.aspx</document>
            </default-documents>
        </rewriter>
    

    Edit: Be sure that where you added the wildcard application map, you also unchecked "Verify that file exists". If you don't do this, default-documents won't do anything.

    Another edit: Found the installation step that illustrates the "Verify that file exists" checkbox. See step 8 here:

    MasterMax1313 : I have all the same configSections listed in yours and SirDemon's responses. I've got the line in the httpModules node. I've got regular rewrite nodes working just fine. It's only the default-document node that isn't working.
    Moose : Check my edit. Where you added the wildcard application map, you also unchecked "Verify that file exists"? Otherwise, it's not going to do default documents..
    MasterMax1313 : Yes, I did check that the IIS settings. That didn't seem to resolve the issue. I'm thinking its the runtime being used.
    Moose : I am using the .Net 2.0 version without problems. Hope you get it figured out.
  • I believe the solution to this problem is the version of .NET I'm using on the website. I'm using the 2.0 runtime and the dll was built for the 1.1 runtime. I saw on the website that the 2.0 runtime is still in RC (since mid 2007), and hence I will not be using it on this production website. Instead, I figured out how to use the URL Rewriting.NET to accomplish the same goal.

    I added the following rule:

    <add name="Redirect54" virtualUrl="~/content/myvirtualpage.aspx"
        rewriteUrlParameter="ExcludeFromClientQueryString"
        destinationUrl="~/content/mydestinationpage.aspx?id=9"
        redirect="None"   
        ignoreCase="true"  />
    

    This causes a HTTP 200 response on the myvirtualpage.aspx, instead of a rewrite. The eventual goal is to have the mydestinationpage.aspx?id=9 have a 301 to myvirtualpage.aspx, which would then serve up the myvirtualpage.aspx with a 200 HTTP response. That's a bit off though.

    SirDemon : Actually, I believe I used the 2.0 version as well and it worked, although, as I said before, with a few annoying bugs we managed to overcome eventually.

0 comments:

Post a Comment