Custom 404 Pages

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Custom 404 Pages

Post by MaryP » Tue Apr 12, 2016 6:41 am

We tried creating a custom 404 page so that users can still navigate our site even if they reach a nonexistent page. The best we've been able to do is 302 redirect to a "Page Not Found" page we've created, which is good on the user side but not optimal for search engines. We also receive two error messages when a user does hit the "Page Not Found" page (pasted below). Is there a way to display a custom 404 page in Able that also serves the correct 404 code to search engines? We are using GoldR8.

Code: Select all

An error has occured at http://www.brewhaus.com/Errors/PageNotFound.aspx?aspxerrorpath=/ScriptResource.axd 
Exception: query did not return a unique result: 2 Stack Trace: at NHibernate.Impl.AbstractQueryImpl.UniqueElement(IList list) at NHibernate.Impl.CriteriaImpl.UniqueResult[T]() at CommerceBuilder.Users.UserRepository.LoadForUserName(String userName, Boolean createMissing) at CommerceBuilder.Services.Membership.WebUserLocator.Locate() at CommerceBuilder.Common.AbleContext.get_User() at CommerceBuilder.Services.PageTracker.Track(HttpApplication application, HttpContext context) at CommerceBuilder.Services.HttpModule.a(Object A_0, EventArgs A_1) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
and

Code: Select all

An error has occured at http://www.brewhaus.com/webpage.aspx?webpageid=34 
Exception: Exception of type 'System.Web.HttpUnhandledException' was thrown. Stack Trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Inner Exception: query did not return a unique result: 2 Inner Exception Stack Trace: at NHibernate.Impl.AbstractQueryImpl.UniqueElement(IList list) at NHibernate.Impl.CriteriaImpl.UniqueResult[T]() at CommerceBuilder.Users.UserRepository.LoadForUserName(String userName, Boolean createMissing) at CommerceBuilder.Services.Membership.WebUserLocator.Locate() at CommerceBuilder.Common.AbleContext.get_User() at AbleCommerce.ConLib.BasketShippingEstimate.Page_Init(Object sender, EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Thank you!

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: Custom 404 Pages

Post by Katie » Tue Apr 12, 2016 8:30 am

In the web.config file there is code to direct the user to a custom 404 page.

Code: Select all

<customErrors mode="On" defaultRedirect="~/Errors/GeneralError.aspx">
      <error statusCode="404" redirect="~/Errors/PageNotFound.aspx"/>
    </customErrors>
This references an existing page which can be customized to help your customers.

Does this help? I'm not sure if I'm addressing the problem with regards to search engines.

Thanks
Katie
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Re: Custom 404 Pages

Post by MaryP » Wed Apr 13, 2016 11:29 am

Hi Katie,
Thanks, we actually have it set up that way, but an SEO company has told us that the search engines are registering these as 302-redirects instead of correctly reading them as 404s, which is undesirable.

Image

Are there any other ways to do a custom 404 page that might work?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Custom 404 Pages

Post by mazhar » Wed Apr 20, 2016 12:04 am

As its discussed here http://stackoverflow.com/questions/4302 ... ttp-status
It seems like its how ASP.NET is dealing with it. Please give a try to the suggested solution by using redirectMode="ResponseRewrite" for customErrors in web.config.

Code: Select all

<customErrors mode="On" defaultRedirect="~/Errors/GeneralError.aspx" redirectMode="ResponseRewrite">
      <error statusCode="404" redirect="~/Errors/PageNotFound.aspx"/>
    </customErrors>
Finally edit Website/App_Code/NavigationHelper.cs and locate following method.

Code: Select all

public static void Trigger404(HttpResponse response, string statusDescription)
        {
            response.Redirect("~/Errors/PageNotFound.aspx");
        }
and update it like

Code: Select all

public static void Trigger404(HttpResponse response, string statusDescription)
        {
            if (HttpContext.Current.IsCustomErrorEnabled)
            {
                throw new HttpException(404, statusDescription);
            }
            else
            {
                response.Clear();
                response.Status = "404 Not Found";
                response.StatusDescription = statusDescription;
                response.End();
            }
        }
Does it make any difference after this change ?

MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Re: Custom 404 Pages

Post by MaryP » Wed Apr 20, 2016 5:11 am

Thanks, Mazhar. I'll let you know the result after my supervisor implements this next week.

MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Re: Custom 404 Pages

Post by MaryP » Wed Apr 27, 2016 6:15 am

Hi mazhar,

We tried the fix that you suggested, and this is the server response we're getting now:

301 - Moved Permanently (http://hotsaucedepot.com/adsdsf) →
302 - Redirect (http://www.hotsaucedepot.com/adsdsf) →
200 - OK (http://www.hotsaucedepot.com/Page-Not-Found.aspx)

Do you have any other suggestions on how we can use a custom 404 page for nonexistent pages that will also return a 404 server response? Thank you for your assistance.

MaryP
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 43
Joined: Wed Oct 22, 2014 10:20 am

Re: Custom 404 Pages

Post by MaryP » Wed Apr 27, 2016 7:39 am

One more thing to add: The code you recommended DID correct the server response ONLY for nonexistent URLs ending in .aspx, so this URL: http://www.hotsaucedepot.com/gdgdfdf.aspx is responding correctly but this one: http://www.hotsaucedepot.com/gdgdfdf is still a 302 redirect. BUT the one that is responding with the correct 404 code is showing a blank page instead of showing hotsaucedepot.com/Page-Not-Found.aspx .

So the goal is to have all nonexistent URLs ending in .aspx, .html, .php or anything else to both return a 404 on the server and also display the page hotsaucedepot.com/Page-Not-Found.aspx to the user.

Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

Re: Custom 404 Pages

Post by Odettes » Sat Apr 30, 2016 11:33 am

MaryP wrote:One more thing to add: The code you recommended DID correct the server response ONLY for nonexistent URLs ending in .aspx, so this URL: http://www.hotsaucedepot.com/gdgdfdf.aspx is responding correctly but this one: http://www.hotsaucedepot.com/gdgdfdf is still a 302 redirect. BUT the one that is responding with the correct 404 code is showing a blank page instead of showing hotsaucedepot.com/Page-Not-Found.aspx .

So the goal is to have all nonexistent URLs ending in .aspx, .html, .php or anything else to both return a 404 on the server and also display the page hotsaucedepot.com/Page-Not-Found.aspx to the user.

This solves your problem:

web.config

Code: Select all

    <system.web>
      <customErrors mode="RemoteOnly" redirectMode="ResponseRewrite">
        <error statusCode="404" redirect="/error.aspx" />
      </customErrors>
    </system.web>

  <system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/error.aspx" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>
error.aspx.cs

Code: Select all

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.StatusCode = 404;
    }
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Custom 404 Pages

Post by Brewhaus » Wed May 25, 2016 5:06 am

I finally got around to implementing this fix, but cannot find the error.aspx.cs file. Can you please let me know which folder it is in, as even a search does not pull it up.

Rick
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: Custom 404 Pages

Post by Katie » Wed May 25, 2016 10:10 am

Hi Rick,

I believe that error.aspx is a custom file that Mr. Berglund has referenced. The default files referenced in your web.config are in the \Errors\ folder.

<customErrors mode="On" defaultRedirect="~/Errors/GeneralError.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/Errors/PageNotFound.aspx"/>
</customErrors>

Thanks
Katie
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Custom 404 Pages

Post by Brewhaus » Wed May 25, 2016 10:58 am

Given that we do not have the custom file, I guess that we need to create one or find another option.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

Odettes
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 102
Joined: Wed Apr 02, 2008 11:00 am
Location: Stockholm, Sweden
Contact:

Re: Custom 404 Pages

Post by Odettes » Tue May 31, 2016 7:33 am

Brewhaus wrote:Given that we do not have the custom file, I guess that we need to create one or find another option.

Just create the page you want to display, error.aspx is just an examplename.
Sincerely,
Thomas Berglund

https://traileronline.se
AbleCommerce Gold R11 Custom

Post Reply