Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Apr 27, 2014 @ 21:10
    Nicholas Westby
    0

    Custom 404 Only Works for Extensionless and ASPX URL's

    When I visit a page that has no extension (e.g., site.com/some-page), I get the 404 page I set up in the umbracoSettings.config. However, when I visit a page with an extension (e.g., site.com/some-page.html or site.com/some-page.jsdgljl), I get a blank response with a 404 HTTP status code (which appears as a blank page).

    Note that I already have this under system.webServer in my web.config:

    <httpErrors errorMode="Detailed" existingResponse="PassThrough" />

    I am doing some route hijacking and I set up a default controller:

    DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(Controllers.CacheController));

    Maybe that interferes with how Umbraco returns 404 pages in some instances? Before I set existingResponse to PassThrough, I was getting ugly IIS error pages (not the ugly Umbraco 404 pages).

    I also followed the instructions here to add a wildcard mapping so all requests go to ASP.NET, though that just seemed to break some things on my site, and returned a 500 error instead of a 404 error on pages with extensions: http://www.iis.net/learn/application-frameworks/building-and-running-aspnet-applications/wildcard-script-mapping-and-iis-integrated-pipeline . Here is a shortened version of the handlers section of my web.config that I tried (but that did not work for me):

    <handlers accessPolicy="Read, Write, Script, Execute">
      <clear />
      <!-- Other handlers removed for brevity. -->
      <add name="TRACEVerbHandler" path="*" verb="TRACE" type="" modules="ProtocolSupportModule" scriptProcessor="" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
      <add name="OPTIONSVerbHandler" path="*" verb="OPTIONS" type="" modules="ProtocolSupportModule" scriptProcessor="" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />
      <!-- These two broke some things on my site. -->
      <add name="ASP.NET-ISAPI-4.0_32bit-Wildcard" path="*" verb="GET,HEAD,POST,DEBUG" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="integratedMode,runtimeVersionv4.0,bitness32" responseBufferLimit="4194304" />
      <add name="ASP.NET-ISAPI-4.0_64bit-Wildcard" path="*" verb="GET,HEAD,POST,DEBUG" type="" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="integratedMode,runtimeVersionv4.0,bitness64" responseBufferLimit="4194304" />
      <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
    </handlers>

    One final note is that ".aspx" pages (e.g., site.com/some-page.aspx) do return the correct 404 page.

    Umbraco 6.1.6. IIS 8.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 28, 2014 @ 12:40
    Jeroen Breuer
    0

    Hello,

    Maybe you could try The new way to do a 404 Umbraco Handler.

    Jeroen

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Apr 29, 2014 @ 17:20
    Nicholas Westby
    1

    Hi Jeroen,

    That didn't seem to work. The code to set the content finder is run, but the function TryFindContent never runs (I excluded some of the code for brevity):

    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
      // This breakpoint is hit.
      ContentLastChanceFinderResolver.Current.SetFinder(new PageNotFoundFinder());
      base.ApplicationStarting(umbracoApplication, applicationContext);
    }
    
    public class PageNotFoundFinder : IContentFinder
    {
      public bool TryFindContent(PublishedContentRequest contentRequest)
      {
        // This breakpoint is never hit.
        return contentRequest.PublishedContent != null;
      }
    }
    

    Same result. Blank page when I visit an HTML URL that doesn't exist (and the correct 404 page when I visit an extensionless URL).

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 29, 2014 @ 17:35
    Jeroen Breuer
    0

    Hmm that's strange. The code should run. I've had some problems with 404's today myself. Maybe that topic can help: http://our.umbraco.org/forum/developers/extending-umbraco/43866-Alternatives-to-404-in-umbracosettingsconfig?p=4#comment180130

    Jeroen

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Apr 29, 2014 @ 17:49
    Nicholas Westby
    0

    Also, I am seeing the HTML URL in Request.RawUrl in my application_BeginRequest and application_EndRequest functions, so I know at least that IIS is passing on the request to the application. Seems like the problem is with Umbraco somewhere.

    Maybe Umbraco sees an extension, assumes the URL is for a static file, and serves up whatever file content it finds... and if it finds no file, it serves up nothing? Seems like others have gotten this to work though, so I'm not sure what would be different about my configuration.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jun 05, 2014 @ 19:41
    Nicholas Westby
    101

    Here is what worked for me in IIS8:

    <httpErrors errorMode="Custom">
        <remove statusCode="404" />
        <error statusCode="404" path="/arbitraryPathThatDoesNotExistAndThatWillRespondWithA404" responseMode="ExecuteURL" />
    </httpErrors>
    

    Note that the errorMode="Custom" may not be necessary (I'm not sure).

  • ZNS 60 posts 198 karma points
    Nov 11, 2015 @ 19:05
    ZNS
    1

    Sorry to dig up an old issue, but this only works for me when using an INotFoundHandler not with a custom IContentFinder. Since the INotFoundHandler is being deprecated in (umbraco 8?) it would be good to get this to work with the IContentFinder also.

  • Matthew Kirschner 323 posts 611 karma points
    Mar 21, 2018 @ 13:42
    Matthew Kirschner
    1

    From what I've gathered, using the httpErrors element negates the need for a custom handler.

    The only issue I see is that it points to a static path instead of an Umbraco node or something else more dynamic.

Please Sign in or register to post replies

Write your reply to:

Draft