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

Forums / Suggestions / sf404->custom 404 without changing url

sf404->custom 404 without changing url

4 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    12 Dec 2008
    Link to this post
    is it possible for 404s to be handled without changing the url? I would like to show my cusom 404 error page, but instead of leaving the url as it is, it redirects it to /my404.aspx?aspxerrorpath=/whateverpage.aspx.

    the reason I'm asking is because google has a snippet you can place on your page to enable "did you mean xxx" kind of behavior, but since every page ends up being my404.aspx, that's all it looks for.

    this is additionally complicated by the fact that I need my404.aspx page to load because it has code to send me an email if a page is not found so that I can fix broken links...

    the need for this would be eliminated if the sf404 page could include report/log functionality with an automated email, as well as being able to be customized to fit the site template/theme, because the sf404 doesn't change the url, but instead throws the generic 404 error page...

    i hope I made sense in this post as it's friday and i'm ready to go home. thanks for listening!
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    15 Dec 2008
    Link to this post
    Hi SelArom,

    I suppose you already set up sf404.aspx (or my404.aspx) page as handler for http 404 status error.

    In the aspx page (named sf404.aspx in Extensionless URLs topic or maybe my404.aspx in your case) you can redirect to the actual aspx page:

    using System;  
    using System.Collections.Generic;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
     
    public partial class sf404 : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            string baseUrl = Request.Url.AbsolutePath ;  
            Response.Redirect(string.Format( "my404.aspx?aspxerrorpath={0}", baseUrl);  
        }  
    }  
     

    Thus when user requests some resource http://server.com/mysite/page.aspx?q=qvalue which does not exist error page (sf404.aspx in my case) will handle the error and will redirect to page
    my404.aspx?aspxerrorpath=/mysite/page.aspx and I suppose, in this page you can put code snippet from google. If it is possible you can do all the job in the same page which handles 404 error and sends the email.

    Also you can create error page to use a master page which is located in the App_Master folder of your website. 

    Let us know if this helps you.

    Kind regards,
    Parvan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    16 Dec 2008
    Link to this post
    but this method still ends  you up at the generic 404.aspx url... what I want to do is leave the url as it is, but show a 404 message. for example, if I go to site.com/stff.aspx the url will say site.com/stff.aspx but the page will have the 404 content, and at the bottom I can put stuff like: did you mean site.com/stuff.aspx?

    i hope that makes sense
  4. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    17 Dec 2008
    Link to this post
    Hello SelArom,
     
    Thank you for contacting us.

    I suppose that you need to intercept when error occurs and append additional html in the output of the error page - you do not want to use custom page, but default error page.

    There is workaround (http://aspnet.4guysfromrolla.com/articles/120308-1.aspx):
    1. You must handle the Error event in the Global.asax file:
    void Application_Error(object sender, EventArgs e)   
        {  
    // here generate suggestion html
            HttpContext.Current.Items.Add("GoogleSuggestion""<H1>Did you mean : <a href='http://google.com'>xxxxxxxxxxx</a></H1>");  
            if( Response.ContentType == "text/html" )  
            {  
                Response.Filter = new CustomResponseFilter(Response.Filter);  
            }  


    2. Put attached file (CustomResponseFilter.cs) in the App_Code of you web site.

    Sincerely yours,
    Parvan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
4 posts, 0 answered