More in this section

Forums / Developing with Sitefinity / changing web.config file resetting sf404 error settings in IIS

changing web.config file resetting sf404 error settings in IIS

5 posts, 1 answered
  1. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    16 Mar 2010
    Link to this post
    hello,

    ive got a test site running on iis 7 asp.net 3.5 and the latest standard release of sitefinity. I set up iis to map 404 errors to sitefinity's sf404.aspx. This gives me the behavior I expected by redirecting pages like site.com/newsroom to site.com/newsroom.aspx.  i have been working with our IT dept for about two hours. We have swapped from a classic to integrated app pool and read countless forum posts.

    ISSUE:  If I make any change in the web.config file, my error page settings are reset in IIS... no more handler.. default generic error page is returned.. 
    Current Environment asp.net 3.5, IIS 7 Integrated Mode. 
    Steps im doing to reproduce(on classic and interated mode app pool)
    Set custom errorpage for 404 to /sf404.aspx (ExecuteURL)
    set or don't set web.config custom error 404 to ~/sf404.aspx
    Start Site
    type in site.com/newsroom/
    status 200 -> view redirected to site.com/newsroom.aspx
    type in site.com/far.gif
    status 404 -> view displays requested path as string
    Open web.config
    add a UrlRewrite rule or change an error page path
    Restart site
    In IIS custom error page reset from sf404 to default...
    This affects all types that arent passed through isapi ( ie. far.gif returns 404 Server page (not sf404)

    This has been reproducable in two different app pools and by changing completely unrelated web.config items. 


    In addition to the Custom Error page being reset, re written urls are not being picked up on by the sf404.aspx page

    so a rewrite like this

       <rule>
            <!-- /newsroom/year.aspx -->
            <url>/newsroom/(\d{4})\.aspx</url>
        <!-- /newsroom.aspx?year=2007 -->
            <rewrite>/newsroom.aspx?Year=$1</rewrite>
          </rule>

    when entering a url like http://site.com/newsroom/2007 is giving me a response like
    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /newsroom/2007.aspx


    It seems that one of these rules would have applied :/

    <rule>
            <!-- /newsroom/year.aspx -->
            <url>/newsroom/(\d{4})\.aspx</url>
        <!-- /newsroom.aspx?year=2007 -->
            <rewrite>/newsroom.aspx?Year=$1</rewrite>
          </rule>
      <rule>
            <!-- /newsroom/year[/] -->
            <url>/newsroom/(\d{4})</url>
            <!-- /newsroom.aspx?year=2007 -->
            <rewrite>/newsroom.aspx?Year=$1</rewrite>
          </rule>


    I just went and added the sf404 directly in the web.config file and now its back to giving me server errors for 404s on aspx pages that arent just missing the extension(even those that clearly apply to a rewrite rule), using an unhandled type sends me right back to the generic error page iis gives as default..


    Please let me know what could be causing these fields to reset everytime I make a change and why reqritten urls are not being matched by the system(they were matching correctly before doing the sf404 change).. It's beginning to get annoying to ask IT to set up the 404 every time I decide we need a new rewrite rule(which we are in development so it's like every 20 minutes).

    Thanks for the help


    ---------Additional Note.
    adding sf404 back to the web.config file gives me this response for the previously working urlrewrite :/
    /sf404.aspx?aspxerrorpath=/newsroom/2007.aspx

    i tried to attach my current web.config in hopes it could help but... Allowed extensions: .gif, .jpg, .jpeg, .png
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Mar 2010
    Link to this post
    Hi Drew Greenwell,

    Thank you for using our services.

    IIS 7 Integrated mode works quite differently than the Classic Pipeline Mode. The sf404.aspx page is used for the Classic Pipeline mode. When you are using the Integrated Pipeline mode all you need to do is to add a wildcard script map to the aspnet_isapi.dll, as in the attached image. To do this open IIS Manager, navigate to your website and go to the Handler Mappings section. Click on Add Wildcard Script Map and add the mapping. You will have to remove the sf404.aspx error page configuration.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    17 Mar 2010
    Link to this post
    Thanks for replying to the post, but I think you misunderstood me. Wildcard mapping every request to asp.net does not seem like a good idea. I dont know of any good reasons for asp.net to have to handle filetypes that we dont tell it to.(an extra layer)[note edited]

    Here are my questions again with less clutter so they will hopefully not be overlooked

    *Why (in integrated or classic mode) does changing the web.config reset the custom error page in IIS?

    *Why have .aspx url Rewrites stopped working since moving to Integrated mode, but extensionless work fine..
    Example:  Web.config CustomErrors = OFF
    This url "/newsroom" takes me to "/newsroom.aspx"
    However this url "/newsroom/2007.aspx" takes me to Server Error(resource not found):
    Requested URL: /newsroom/2007.aspx
    This rewrite rule is in place which was working flaswlessly before swapping to Integrated mode :/
        <rule>
            <!-- /newsroom/year.aspx -->
            <url>/newsroom/(\d{4})\.aspx</url>
        <!-- /newsroom.aspx?year=2007 -->
            <rewrite>/newsroom.aspx?Year=$1</rewrite>
          </rule>


    We really do need to address this type of scenario now before we can move forward with our clients.


    Thanks in advance for taking the time to read and understand my question before replying.
  4. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    18 Mar 2010
    Link to this post
    Just figured out half of this. When using Integrated mode you have to make sure that you have the url rewrite module registered in both the httpmodules section and in the modules section of the web.config. This may be a known for every one else, but i didnt catch it until I read the article explaining how to avoid using wildcard mapping with IIS 7 and integrated mode on learn.iis.net (search "wildcard")

    So problem 2 is fixed by doing this here. Problem one still confuses me though.(it makes more sense to 404 at the iis level and pass to asp.net then to pass through iis to asp.net and then 404, at least for unhandled filetypes anyway)
    <system.webServer>
        <modules>
          ...
          <!--<add name="Cms" type="Telerik.Cms.Web.CmsHttpModule, Telerik.Cms"/>-->
          <add name="Cms" type="Telerik.Cms.Web.CmsHttpModuleUrlRewrite, Telerik.Cms"/>
          <!-- Http Module for extension mappings in Library module.-->
          <!--<add name="LibraryModule" type="Telerik.Libraries.LibraryHttpModule, Telerik.Libraries"/>-->
          <add name="RadUploadModule" preCondition="managedHandler" type="Telerik.Web.UI.RadUploadHttpModule, Telerik.Web.UI"/>
        </modules>
     
     
     
     
     
    <!-- I already had this from the tutorials (WHICH IS ALL YOU NEED FOR CLASSIC MODE)-->
     
     <httpModules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <!--<add name="Cms" type="Telerik.Cms.Web.CmsHttpModule, Telerik.Cms"/>-->
          <add name="Cms" type="Telerik.Cms.Web.CmsHttpModuleUrlRewrite, Telerik.Cms"/>
          <!-- Http Module for extension mappings in Library module.-->
          <!--<add name="LibraryModule" type="Telerik.Libraries.LibraryHttpModule, Telerik.Libraries"/>-->
          <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule, Telerik.Web.UI"/>
        </httpModules>



    Anyway, I didnt mean to come off as rude in my previous post. I really appreciate the product you have all produced and the obvious effort that you put into it. We really do have 4 clients on the table that we are moving forward with already this year. Thanks again I look forward to a lasting business relationship.
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    19 Mar 2010
    Link to this post
    Hi Drew Greenwell,

    Thank you for getting back to me.

    I am happy to hear you have managed to figure it our by yourself. It completely flew off my mind that you might have not set the HttpModule in the system.webServer/modules section. By default we keep two configuration settings (system.web and system.webServer) as Sitefinity websites can be run in both modes of IIS. As you will notice all of our HttpModules and HttpHandlers are declared in system.web and system.webServer respectively for IIS 6.0 and IIS 7.0 integrated pipeline mode.

    As far as the web.config settings overriding IIS settings, to my knowledge it is default that configurations in child configuration files override configurations in parent ones in ASP.NET. You can gather more information here:
    ASP.NET Configuration File Hierarchy and Inheritance
    How to: Lock ASP.NET Configuration Settings

    Regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
Register for webinar
5 posts, 1 answered