+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / 404 - Odd behavior

404 - Odd behavior

11 posts, 0 answered
  1. Allen
    Allen avatar
    71 posts
    Registered:
    04 Aug 2007
    04 May 2008
    Link to this post
    I have added a page which I set in my web config to handle 404 errors.  However, it is simply ignored and the standard "Page Cannot Be Found" error is displayed.  So, I decided to test changing the information in the IIS manager.  When doing this, the page (URL) I set is displayed, but none of the Stylesheet settings from the MasterPage get rendered.  This is true if I use either a "normal" ASPX page or a managed page.  Has anyone else reported this odd behavior? 

    I am using IIS 6.0 and SF 3.0 sp2.
    (PS - Web.config DOES have errors section set to "RemoteOnly")
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    08 May 2008
    Link to this post
    Hi Allen,

    You mentioned that your error settings are "Remote Only". This means that only people who are accessing from locations different from localhost, will see the actual 404 page that you set. If you are trying to access a non-existing page, you will see the regular 404 page. If you set "On" instead "Remote Only", then you will also see the new 404 page.
    The problems with the stylesheets maybe be caused be wrong relative paths. Could you try using absolute ones, so you are sure that stylesheet file is reached? For example, if your CSS file is located in:
    \[YourProject]\styles\mystyle.css
    the absolute path would be:
    ~/styles/mystyle.css

    Let us know if we understand you correctly or if there is anything else we could assist you with.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    16 Sep 2008
    Link to this post
    Hello,

    Regarding the stylesheets not being displayed... i have the same issue.  I created an Error404.aspx page as a page in Sitefinity site structure (so it's not a physical aspx file, it is a page in the sitemap), because I want it to use a template that already has pre-defined look and feel (also site navigation, etc.).

    I have added a 404 error redirect in web.config, but that only works when the requested [non-existent] page has aspx extension.  Then I found that using IIS 404 custom error redirect to URL "/home/error404.aspx" I can redirect all 404 errors to the correct page in sitemap, but that's where the stylesheets are gone (but the page content is displayed fine).

    A template that's using those stylesheets is simply set to use a specific THEME, which has stylesheets defined in it.  But the theme doesn't seem to be used when IIS redirects to /home/error404.aspx.

    How to solve this?  I would like NOT to have to create a standalone physical aspx page for which I would have to re-add all elements that are already part of the specific site template.  Help is appreciated!

    Thanks.
  4. Joe
    Joe avatar
    138 posts
    Registered:
    24 Sep 2012
    17 Sep 2008
    Link to this post
    Hi Marko,

    Thanks for contacting us.

    The solution is to drag your CSS from your theme onto the error page, so that the error page knows to use that CSS. To achieve this functionality, follow these steps:

    1. In your Web.config, add the following highlighted line:
    <customErrors mode="On"
                <error redirect="~/Sitefinity/nopermissions.aspx" statusCode="403"/> 
                <error redirect="~/404ErrorPage.htm" statusCode="404"/> 
            </customErrors> 

    2. In your Sitefinity project, create a page called 404ErrorPage.htm and place some text on it and give it h4 tags, or another tag that is styled in your CSS
    3. From the Levels Theme, or another theme in your App_Themes folder, drag the CSS onto the 404ErrorPage.htm
    4. On your Sitefinity website, type in the name of a page that does not exist, such as mysite.com/yahoo.aspx

    I have also attached a code sample to demonstrate this functionality. Please let us know if you need further assistance.

    Greetings,
    Joe
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    18 Sep 2008
    Link to this post
    Thanks, I'll try this... BUT... this won't really satisfy my particular scenario requirements.  Like I said, I created an Error404.aspx page in sitefinity sitemap (it's a page just like any other, it is assigned to a template, and therefore it's displaying all template components, such as site-wide navigation bars, etc.).  I did this because I want my 404 error page to look like the rest of the site, with all template settings.  So in trying to redirect 404 error TO THAT PAGE (Error404.aspx), my styles break.

    I can't really "drag" any css onto this file, because it is NOT a "file" in the file system, but a sitemap page in sitefinity database.

    So is there a way to get it to work THAT way, or does a 404 page HAVE TO BE a standalone file???

    Are there any official recommendations/scenarios for handling errors (like 404) in sitefinity?
  6. Allen
    Allen avatar
    71 posts
    Registered:
    04 Aug 2007
    18 Sep 2008
    Link to this post
    I agree that this solution doesn't really satisfy my want/need.

    I also want to have the error page support my page's "template" page layout with menus and such - basically, to have the page be an exact replica of my other site pages.  The only difference is that I would want the body of the page to read, "File not found."  True enough, I can copy my master page and "drag" the CSS file onto it so that the container mark up is correct, but all of the menu information is stored in the CMS database.

    Interestingly, I have no problem generating the "nice" error page when a user mistypes a page name (e.g. [root]/default1.aspx instead of [root]/default.aspx).  The trouble only arises when the user tries a slashed URL (e.g. [root]/somefolder/) but an "unslashed" (sorry not a real word - e.g.[root]/somefolder) works as expected. 

    I realize that the issue revolves around the URL rewriting, but I wish there were better support for "folder" browsing.  I believe that this would not only resolve this issue, but it would be a more natural URL navigation to most users.

    That's my two cents.

    Thanks

  7. Bob
    Bob avatar
    330 posts
    Registered:
    24 Sep 2012
    26 Sep 2008
    Link to this post
    Hello Allen,

    Unfortunately I’m unable to reproduce this behavior. What version are you using? I remember there was such problem in the past but it was fixed in v3.2.1616. All style sheets in the theme ware correctly applied in my test with slashes and without slashes.

    Can you confirm the version you are using?
    If Sitefinity’s version is the same, can you give us more details (OS, IIS and .Net versions)?

    Ideally, you could send us a small project reproducing the problem.

    Greetings,
    Bob
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    30 Oct 2008
    Link to this post

    I was experiencing this same behavior. 

    First, you set your web.config to redirect for a 404, like:

    <customErrors mode="RemoteOnly">
        <error redirect="~/Sitefinity/nopermissions.aspx" statusCode="403" />
        <error redirect="~/PageNotFound.aspx" statusCode="404" />
    </customErrors>

    Now if you go to a page with an ASPX extension like:
    http://www.mywebsite.net/OurCompany/foobar.aspx

    you see the 404 error page as it should be rendered (with one issue, see below).

    If you go to a page without an extension:
    http://www.mywebsite.net/OurCompany/foobar

    you get whatever IIS is configured to show, because SF isn't handling this one.  

    If I now set the IIS custom error for a 404 to URL and the target to /PageNotFound.aspx, I get the content from the custom PageNotFound page, but without the CSS applied, and all images missing (along with any other linked content, such as javascript).

    However, if you look at the source code, each page is identical except for the form tag action.

    The problem is that in the case where I look for a non-aspx page, SF doesn't handle the response, IIS does.  IIS doesn't send a 302 redirect.  I suspect it's a server.transfer rather than a redirect.  It would be great if that could be changed.

    At any rate, if IIS handles it, the final URL as far as the browser is concerned is still the original URL, and Sitefinity rewrites the stylesheet URL (as well as any others with the ~ token) to be relative to what it thinks is the current folder, the root.  But the browser thinks the page is somewhere else, so it will never find the stylesheet or other linked items.

    Anyway, what I did to temporarily fix this whole situation was to create a redirect page, called 404Redirect.aspx, which I put in the web site root.  It contains these lines:

    <%@Page Language="c#"%>
    <%@OutputCache Duration="604800" VaryByParam="None" %>
    <%Response.Redirect("/PageNotFound.aspx"); %>

    Then you configure IIS to redirect to this page on a 404.  Once I did that, I end up on the SF page I created for the 404. 

    Unfortunately, I lose the original error page information because of the extra redirection.  I'm going to either write an HttpHandler or else modify my 404Redirect.aspx to try to recover that information, as it's important to know.  Of course, I can always look at the IIS logs for this, but I have a nice web tracking application that will give this information to the folks that are in charge of the content.

    Ok, one more issue with the Sitefinity part.

    If you ask for an ASPX page that doesn't exist, then SF handles it with a 302 then a 200 when it renders the PageNotFound.aspx page. This is wrong!  It should return a 404 on the final page when it handles the error page from the web.config. 

    This is a big problem, because the page won't be removed from search engine indexes, and folks will continue to get this error page.  So to hack a fix for this, until Telerik addresses the issue (or maybe there is a fix, and I don't know about it), you can create a separate master page template for error pages.  Then you put some code in there that either looks to the http_referer header to find out where the user came from, in order to determine the actual error status code, or you create a new master page for each of the major error types.  The object of the code is to write an HTTP status code.  So, you might try a master page something like this:

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="ErrorPages.master.cs" Inherits="App_Master_ErrorPages" %>
    <% Response.StatusCode = 404; %>

    <rest of master page code here>

    It's important to write the status code before you send any text to the browser!

    A while back I wrote a nifty redirection handler for MCMS 2002. Whenever a page not found error occured, it would look up the old URL in a list that was maintained by the web content folks.  Whenever they'd move stuff around on the site, they'd make an entry in this list, mapping the old URL to the New one.  If they moved a whole subtree of the site, they would only have to enter the top folder that was moved.  You'll see why in a moment.

    The algorithm went like this:

    1.  It checked the entire URL first, looking for a match.  If it found one, it redirected (with a 301 moved permanently) to the new page. 

    2.  If it didn't find one, it recursively walked up the URL looking for matches at the folder level.  If it found one, it looked up the new URL for the folder, and looked to see if that original page still exists in the new folder's subtree.  If so, it issues a 301 and redirects.

    3.  If it didn't find the page in the new subtree, it issued a 302 and redirected to the folder default page that it just matched. 

    4.  If it never finds one at all, it logs the problem and redirects to the Page Not Found page, which then issues a 404. 

    This has the advantage of retaining your page rank for inbound links to pages that have been moved on your site (the 301), but purges a search engine's index of pages that don't truly exist.  Also, I noticed a drastic reduction in 404 errors, because a lot of the time the page was still there, but only moved.

    Problem solved.  Now I just have to write a module like this for Sitefinity! ;^)

    Regards,
    Mike Sharp

     

  9. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    14 Nov 2008
    Link to this post
    Hello Mike,

    Thank you for your follow up and detailed explanations! We brought this for a discussion in the team and reached some valuable conclusions.
    This post also helped to some of our customers. We are updating your Telerik account for your opinion and experience shared.

    Regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Palmer
    Palmer avatar
    1 posts
    Registered:
    22 Jul 2009
    22 Jul 2009
    Link to this post
    Hi -

    I am experiencing the same issue. Has this been fixed or is the workaround given by Mike the recommended solution?

    Thanks,

    Robin
  11. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Jul 2009
    Link to this post
    Hi Robin Palmer,

    We have fixed this. I am testing with Sitefinity 3.6SP2, and the response code is 404 instead of 200 when using the sf404.aspx approach.

    All the best,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
11 posts, 0 answered