« Previous Next »

Thread: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

Last post 01-07-2009 6:03 AM by ricishay. 11 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (12 items)

Sort Posts:

  • 12-17-2008, 9:07 AM

    (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Hi,

    I'm using Intelligencia.UrlRewriter from UrlRewriter.Net 

    I've been developing my site on VS2008 Express.
    And everything works ok.

    I have recently installed IIS7 on my machine, to load as localhost, to ensure and test that everything is working before I publish the site.

    However, the URLRewriter no longer works when I publish as local. (It was previously working fine when I worked through VS2008.

    Web.Config:

    <rewrite url="~/Test1/(.+)" to="~/TestUrlRewrite.aspx?PageContentUrl=Test1/$1"></rewrite> 

    In VS2008:

    This works absolutely fine. 

    In IIS7.0 as localhost:

    "http://localhost/App/test1" --> the Requested URL becomes "/App/test1/rlRewrite.aspx"

    http://localhost/App/test1/asdf --> the Requested URL becomes "/App/test1/asdf/rite.aspx"

    http://localhost/App/test1/1234567890 --> the Requested URL becomes "/App/test1/1234567890/spx"

     

    Why is the webserver rewriting the URLs wrongly? (It's appending the last few letters of the target URL...)

    What is wrong here?

    Greatly appreciate if someone can help me.

    Thanks!

     

  • 12-17-2008, 1:29 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 660

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Are you using Vista SP1 with the latest .NET framework 3.5 SP1? I remember seeing a similar problem when IIS 7 was used on Vista not SP1.

    http://ruslany.net
  • 12-17-2008, 9:35 PM In reply to

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Hi Ruslany,

    Thanks for the reminder.
    But YES, I've got 3.5 SP1 installed and running.

    It's really strange that IIS is appending the last few characters of the target URL into the "rewritten" url.

     

     

  • 12-20-2008, 12:05 PM In reply to

    • dgdev
    • Top 500 Contributor
    • Joined on 11-16-2008, 3:22 AM
    • Posts 18

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

     The intelligencia urlrewriter still has several bugs. I believe I had that same issue you did...

    Try formatting your regex like so:

    <rewrite url="^~/Test/?(.*)$" to=".........." />

    The use of the ".+" is incorrect and should be a ".*"
    Also, adding the "?" allows your urls to work without the trailing "/"

  • 12-21-2008, 9:11 AM In reply to

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Hi dgdev,

    Thanks for the note.
    I did what you suggested, and it's still not working. 

    Here's my web.config:

        <system.webServer>       
            <modules runAllManagedModulesForAllRequests="true">
                <remove name="ScriptModule"/>
                <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
            </modules>

            <validation validateIntegratedModeConfiguration="false"/>
           
            <handlers>
                <remove name="ScriptHandlerFactory"/>
                <remove name="ScriptHandlerFactoryAppServices"/>
                <remove name="ScriptResource"/>
                <remove name="WebServiceHandlerFactory-Integrated"/>
                <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
               
                <add name="ASP.NET-ISAPI-2.0-Wildcard"
                   path="*" verb="GET,HEAD,POST,DEBUG"
                   modules="IsapiModule"
                   scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
                   preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />


            </handlers>
        </system.webServer>
       
        <rewriter>

            <rewrite url="^~/Test1/(.*)$" to="~/TestUrlRewrite.aspx?PageContentUrl=Test1/$1" processing="stop"></rewrite>
            <rewrite url="^~/Test1/$" to="~/TestUrlRewrite.aspx?PageContentUrl=Test1" processing="stop"></rewrite>
            <rewrite url="^~/AboutUs$" to="~/Pages/Default.aspx?PageContentUrl=AboutUs" processing="stop"></rewrite>

        </rewriter>

     

    The above rules all work when I'm working on VS2008. (e.g. http://localhost:2649/App).
    The rewrites are all ok and successful.

    However, when I use this through IIS7.0, using http://localhost/App... the problems are below.

     

    Problem. 

    The rewrite:
    http://localhost/App/test1/ --> Requested URL: /App/test1/lRewrite.aspx
    http://localhost/App/test1/1 --> Requested URL: /App/test1/1/Rewrite.aspx
    http://localhost/App/test1/12 --> Requested URL: /App/test1/12/ewrite.aspx
    http://localhost/App/test1/12345 --> Requested URL: /App/test1/12345/ite.aspx
     
     
    There is a pattern here:
    My target URL filename is : "TestUrlRewrite.aspx" (<- let this be called "TargetFileName").
    The server is rewriting the URL minus the length of the "source" URL, starting from "test1".
     
    For example,
    http://localhost/App/test1/12345 --> Requested URL: /App/test1/12345/ite.aspx
     
    Length of "test1/12345" is 11.
    The targetURL will be rewritten right(TargetFileName, len(TargetFileName) - 11) = "ite.aspx" where the first 11 characters ("TestUrlRewr") have been removed/truncated.
     
     
    HOWEVER
    If however, I exceed the length of TargetFileName, the URLRewriting works!
     
    http://localhost/App/test1/12345123123123123 --> The server brings me to the target page. :)
     
     
    Hope I'm making sense, and you're following my details.

    Hope you can help. :)

  • 12-21-2008, 10:41 AM In reply to

    • dgdev
    • Top 500 Contributor
    • Joined on 11-16-2008, 3:22 AM
    • Posts 18

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

     

    I'm still looking into your problem as I've never had this happen:

    1. What's your IIS setup: Classic or Integrated?

    2. Have you modified any code the UrlRewriter?

    3. Your 2nd rewrite rule is redundant as the first one will always trigger, then processing stops.
    You might want to delete the second one as it's not needed and change the first one to:
    <rewrite url="^~/Test1/?(.*)$" to="~/TestUrlRewrite.aspx?PageContentUrl=Test1/$1" processing="stop" />

    I'm looking into more possibilities, but it definitely seems like it would either be a IIS issue or Rewriter bug.

  • 12-21-2008, 1:16 PM In reply to

    • dgdev
    • Top 500 Contributor
    • Joined on 11-16-2008, 3:22 AM
    • Posts 18

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Also don't forget to add this rule at the top of all your others:

    <rewrite url="^(/.*(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.axd)(\?.*)?)$" to="$1" processing="stop" />

    After some debugging, I realized everything was pouring through my rewriter. So if you have 50 images on your page, its all going through Intelligencia's rewriter.

    This actually only helps it a little bit however. The rewriter still executes several functions for each file.

    The best solution would be to write a simple if statement that checks the url requested. If it's one of the file types listed above, then it won't call the rewrite() method.

    For intelligencia, this would be done before _rewriter.Rewrite(); is called in the RewriterHttpModule file.

  • 12-23-2008, 11:50 AM In reply to

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Hi dgdev,

    Here's my updated web.confg:<rewriter>
        <rewrite url="^(/.*(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.axd)(\?.*)?)$" to="$1" processing="stop" />
         <rewrite url="^~/Test1/?(.*)$" to="~/TestUrlRewrite.aspx?PageContentUrl=Test1/$1" processing="stop"></rewrite>
        <rewrite url="^~/AboutUs$" to="~/Pages/Default.aspx?PageContentUrl=AboutUs" processing="stop"></rewrite>
    </rewriter>
    It’s still rewriting to the previous URLs: The rewrite:
    http://localhost/App/test1/ --> Requested URL: /App/test1/lRewrite.aspx
    http://localhost/App/test1/1 --> Requested URL: /App/test1/1/Rewrite.aspx
    http://localhost/App/test1/12 --> Requested URL: /App/test1/12/ewrite.aspx
    http://localhost/App/test1/12345 --> Requested URL: /App/test1/12345/ite.aspx
     
    Answering your questions: 1. What's your IIS setup: Classic or Integrated?·         Integrated.·         Would you recommend the Classic mode? 2. Have you modified any code the UrlRewriter? ·         No, I’ve not.

     

  • 12-25-2008, 8:56 AM In reply to

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Hi dgdev,

    I've changed my IIS mode from Integrated to Classic, and it works.

    I was hesitant in doing this, because I'm not sure the impact in classic mode to my ASP.NET 3.5 website and applications.

    Can you please advise what's the difference between Integrated and Classic mode?

    Thanks!

     

     

  • 12-30-2008, 1:17 AM In reply to

    • ricishay
    • Not Ranked
    • Joined on 04-30-2008, 10:44 AM
    • Posts 7

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    Hello,

    i m using Intelligencia.UrlRewriter.dll and http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/ this to do url rewrite.Its working fine on iis 5 and iis6 but its not working on IIS 7 .i am getting 404 page not found error.Please help

    please have a look at my webconfig file

    <modulesSection>

    <rewriteModule>

    <rewriteOn>true</rewriteOn>

    <rewriteRules>

    <rule source="index.aspx" destination="home.aspx" />

    <rule source="user/(\w+)/index.aspx" destination="user/citybystate.aspx?StateCode=$1" />

    <rule source="user/(\w+)/(\w+)/index.aspx" destination="results.aspx?StateCode=$1&amp;CityName=$2" />

    <rule source="users/profile/(\w+)/(\w+)/(\w+)/(\w+)/index.aspx" destination="profile.aspx?ListingName=$1&amp;ListingId=$2&amp;CityName=$3&amp;StateCode=$4" />

    <rule source="user/secondrykeyphrase/(\w+)/(\w+)/index.aspx" destination="listingbysecondrycity.aspx?SecondaryKeyPhraseNameId=$1&amp;CityName=$2" />

    <rule source="users/category/(\w+)/(\w+)/(\w+)/(\w+)/index.aspx" destination="listingbysecondarycity.aspx?SecondaryKeyPhraseName=$1&amp;SecondaryKeyPhraseId=$2&amp;CityName=$3&amp;StateCode=$4" />

    <rule source="users/sorted/(\w+)/(\w+)/(\w+)/index.aspx" destination="sortedlisting.aspx?LetterName=$1&amp;StateCode=$2&amp;CityName=$3" />

    <rule source="users/page/(\w+)/(\w+)/(\w+)/index.aspx" destination="results.aspx?CityName=$1&amp;StateCode=$2&amp;PageNo=$3" />

    <rule source="users/page/(\w+)/(\w+)/(\w+)/(\w+)/index.aspx" destination="sortedlisting.aspx?CityName=$1&amp;StateCode=$2&amp;PageNo=$3&amp;LetterName=$4" />

    </rewriteRules>

    </rewriteModule>

    </modulesSection>

  • 01-07-2009, 6:02 AM In reply to

    • ricishay
    • Not Ranked
    • Joined on 04-30-2008, 10:44 AM
    • Posts 7

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    i am getting 404 error on iis 7..my web.config is

     

    <?xml version="1.0" encoding="UTF-8"?>

    <configuration>
      <configSections>
        <section name="rewriter" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
      </configSections>
        <appSettings />
      <connectionStrings>
        <add name="Connection" connectionString="Data Source=;Initial Catalog=mymassagedir_massagedir;User ID=massagedir;Password=elance12" />
      </connectionStrings>
        <system.web>
          <customErrors mode="Off"></customErrors>
            <!--
                Set compilation debug="true" to insert debugging
                symbols into the compiled page. Because this
                affects performance, set this value to true only
                during development.
            -->
            <compilation debug="true" />
            <!--
                The <authentication> section enables configuration
                of the security authentication mode used by
                ASP.NET to identify an incoming user.
            -->
            <authentication mode="Windows" />
            <!--
                The <customErrors> section enables configuration
                of what to do if/when an unhandled error occurs
                during the execution of a request. Specifically,
                it enables developers to configure html error pages
                to be displayed in place of a error stack trace.

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm"/>
                <error statusCode="404" redirect="FileNotFound.htm"/>
            </customErrors>
            -->
        </system.web>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="ScriptModule" />
          <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
        </modules>

        <validation validateIntegratedModeConfiguration="false" />

        <handlers accessPolicy="Read, Execute, Script">
          <remove name="ScriptHandlerFactory" />
          <remove name="ScriptHandlerFactoryAppServices" />
          <remove name="ScriptResource" />
          <remove name="WebServiceHandlerFactory-Integrated" />
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="classicMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="ScriptResource" preCondition="classicMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

          <add name="ASP.NET-ISAPI-2.0-Wildcard" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />


        </handlers>
      </system.webServer>

      <rewriter>
        <rewrite url="~/user/(\w+)/index.aspx" to="~/user/citybystate.aspx?StateCode=$1" processing="stop" />
        <!--<rewrite url="^~/home.aspx$" to="home1.aspx" processing="stop"></rewrite>
        <rewrite url="^~user/(\w+)/index.aspx" to="~user/citybystate.aspx?StateCode=$1" processing="stop"></rewrite>-->

       

      </rewriter>
    </configuration>
     

  • 01-07-2009, 6:03 AM In reply to

    • ricishay
    • Not Ranked
    • Joined on 04-30-2008, 10:44 AM
    • Posts 7

    Re: (Intelligencia.UrlRewriter) IIS7 not redirecting URL

    i am getting 404 error on iis 7..my web.config is

     

    <?xml version="1.0" encoding="UTF-8"?>

    <configuration>
      <configSections>
        <section name="rewriter" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
      </configSections>
        <appSettings />
      <connectionStrings>
        <add name="Connection" connectionString="Data Source=;Initial Catalog=mymassagedir_massagedir;User ID=massagedir;Password=elance12" />
      </connectionStrings>
        <system.web>
          <customErrors mode="Off"></customErrors>
            <!--
                Set compilation debug="true" to insert debugging
                symbols into the compiled page. Because this
                affects performance, set this value to true only
                during development.
            -->
            <compilation debug="true" />
            <!--
                The <authentication> section enables configuration
                of the security authentication mode used by
                ASP.NET to identify an incoming user.
            -->
            <authentication mode="Windows" />
            <!--
                The <customErrors> section enables configuration
                of what to do if/when an unhandled error occurs
                during the execution of a request. Specifically,
                it enables developers to configure html error pages
                to be displayed in place of a error stack trace.

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm"/>
                <error statusCode="404" redirect="FileNotFound.htm"/>
            </customErrors>
            -->
        </system.web>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="ScriptModule" />
          <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
        </modules>

        <validation validateIntegratedModeConfiguration="false" />

        <handlers accessPolicy="Read, Execute, Script">
          <remove name="ScriptHandlerFactory" />
          <remove name="ScriptHandlerFactoryAppServices" />
          <remove name="ScriptResource" />
          <remove name="WebServiceHandlerFactory-Integrated" />
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="classicMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="ScriptResource" preCondition="classicMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

          <add name="ASP.NET-ISAPI-2.0-Wildcard" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />


        </handlers>
      </system.webServer>

      <rewriter>
        <rewrite url="~/user/(\w+)/index.aspx" to="~/user/citybystate.aspx?StateCode=$1" processing="stop" />
        <!--<rewrite url="^~/home.aspx$" to="home1.aspx" processing="stop"></rewrite>
        <rewrite url="^~user/(\w+)/index.aspx" to="~user/citybystate.aspx?StateCode=$1" processing="stop"></rewrite>-->

       

      </rewriter>
    </configuration>
     

Page 1 of 1 (12 items)
Microsoft Communities