For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
-
MaryP
- Lieutenant, Jr. Grade (LT JG)
- Posts: 43
- Joined: Wed Oct 22, 2014 10:20 am
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!
-
Katie
- AbleCommerce Admin
- Posts: 2651
- Joined: Tue Dec 02, 2003 1:54 am
-
Contact:
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
-
MaryP
- Lieutenant, Jr. Grade (LT JG)
- Posts: 43
- Joined: Wed Oct 22, 2014 10:20 am
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.
Are there any other ways to do a custom 404 page that might work?
-
mazhar
- Master Yoda
- Posts: 5084
- Joined: Wed Jul 09, 2008 8:21 am
-
Contact:
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)
- Posts: 43
- Joined: Wed Oct 22, 2014 10:20 am
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)
- Posts: 43
- Joined: Wed Oct 22, 2014 10:20 am
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)
- Posts: 102
- Joined: Wed Apr 02, 2008 11:00 am
- Location: Stockholm, Sweden
-
Contact:
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;
}
-
Brewhaus
- Vice Admiral (VADM)
- Posts: 878
- Joined: Sat Jan 19, 2008 4:30 pm
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
-
Katie
- AbleCommerce Admin
- Posts: 2651
- Joined: Tue Dec 02, 2003 1:54 am
-
Contact:
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
-
Brewhaus
- Vice Admiral (VADM)
- Posts: 878
- Joined: Sat Jan 19, 2008 4:30 pm
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)
- Posts: 102
- Joined: Wed Apr 02, 2008 11:00 am
- Location: Stockholm, Sweden
-
Contact:
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.