Umbraco: How to get rid of "This page is intentionally left ugly" - umbraco

Help me get rid of the default 400 page
I've implemented a IContentFinder and added it as a ContentLastChanceFinderResolver. Just like it's explained here: https://our.umbraco.org/documentation/reference/routing/request-pipeline/icontentfinder
This works flawless!!
%25c3
But for certain url's I still see the "This page is intentionally left ugly" system 404 page.
Ex: http://example.com/test%25c3
On umbraco.com just a blank page is returned: https://umbraco.com/test%25c3
How do I get this behaviour?
I've also tried using the configuration-way to set the 404 page, but it still shows the "This page is intentionally left ugly" page.
In /config/umbracoSettings.config:
<errors>
<error404>1105</error404>
</errors>
XSS
The reason I want to remove the"This page is intentionally left ugly" page is that it allow for cross site scripting attack since it will output what ever you type in the url.
That means if you add a script tag to the url it'll get executed on the "left ugly" page

The url /test%25c3 give a:
HTTP Error 404.11 - Not Found
The request filtering module is configured to deny a request that contains a double escape sequence.
Use the IIS error handeling.
In the web.config
place below the <system.webServer>
<httpErrors errorMode="Custom">
<error statusCode="404" subStatusCode="11" path="/error.html" responseMode="ExecuteURL" />
</httpErrors>
And create a error.html file, blank or if you like with some text.
There are many more errors. Try this url for example http://umbraco.com/* or http://umbraco.com/lpt1
more about the error page and a .NET CMS, like Umbraco or Sitecore you can read here: Sitecore and the error page it is also on some Umbraco situations.

Related

Page not found - No umbraco document matches the url

When typing in a url that does not exist I want to display a custom 404 page however when I type in a non-existing page I am seeing a Page not found No umbraco document matches the url in the browser
At present I am to running multiple websites in one umbraco v6.2.5 application and there are multiple languages for each website for example the following:
- www.mydomain.com/en
- www.mydomain.com/de
- www.mydomain.com/fr
The config\404handlers.config consists of the following:
<?xml version="1.0" encoding="utf-8" ?>
<NotFoundHandlers>
<notFound assembly="umbraco" type="SearchForAlias" />
<notFound assembly="umbraco" type="SearchForTemplate"/>
<notFound assembly="umbraco" type="SearchForProfile"/>
<notFound assembly="uComponents.NotFoundHandlers" type="MultiSitePageNotFoundHandler" />
<notFound assembly="umbraco" type="handle404"/>
</NotFoundHandlers>
The document type and template have been created and the template has been assigned to the new 404 node but it is still not working.
I can see that the issue is related to the subdomain as when I remove these (i.e en/, de/, fr/) from the culture and hostnames the 404 page starts working but this is required to differentiate between the languages..
Can someone please suggest how I can get the 404 page to work with the subdomains, thanks!

ASPNET HttpErrors redirect to controller

In my web config I have this setting:
<httpErrors errorMode="Custom" defaultPath="/Error/Error/ErrorHandler/404" defaultResponseMode="ExecuteURL" />
I would like to redirect all IIS errors to go to my own controller and action. However I get the error:
The requested page cannot be accessed because the related configuration data for the page is invalid.
However, If I try to redirect specific error codes to my controller, it will work. E.g:
<httpErrors errorMode="Custom" >
<remove statusCode="403"/>
<error statusCode="403" responseMode="ExecuteURL" path="/Error/Error/ErrorHandler/404"/>
</httpErrors>
How can I change my default redirect to go to my controller/action?
Looks like this is not possible. responseMode only supports:
File for unprocessed files, like .html
ExecuteURL supports .aspx files
Redirect to redirect to a different page which is not recommended from a SEO perspective.
You could try the answer from mono blaine in this post: CustomErrors vs HttpErrors - A significant design flaw?

MVC Custom errors not working in IIS8.5 (but working locally)

I can't get ANY custom error pages to appear in IIS8.5!
When I run my MVC 5 app locally in Visual Studio, custom error pages are displayed. But when I deploy to IIS on my webserver, and navigate to the site sub-page with a 'bad URL' my custom 404 page should be displayed, but the default generic 404 page is shown instead.
Here is what I've done:
web.config
customError section has been deleted.
Added the following section
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error/ServerError" />
</httpErrors>
</system.webServer>
Controller
namespace MyApp.Controllers
{
[Authorize(Roles = "MyRole")]
public class ErrorController : Controller
{
[AllowAnonymous]
public ActionResult NotFound()
{
Response.StatusCode = 404;
return View();
}
[AllowAnonymous]
public ActionResult ServerError()
{
Response.StatusCode = 500;
return View();
}
}
}
Views
Very simple and straight forwards (not included here).
IIS
Verified the IIS Error Page feature is identical to what's in my config. A page for each error status code. Feature and Pages are set to 'custom'.
Checked Windows Features\Web Server (IIS)\Web Server\Common HTTP Features\HTTP Errors is installed.
Developer Tools
Navigating to a sub-page spelt incorrectly shows I'm getting a 404 Client Error.
Help
I've tries many things! Am I missing something? IIS environmental issue, i.e. a setting somewhere?
Custom errors work in my IDE but not on IIS. I've spent over a day on this! Read many pages, articles, and similar questions on SO.
After several days of investigating, finally found the issue.
In IIS, my website was residing as an Application under the Default Web Site, e.g. Default Web Site\MyDevSite. (All my dev sites are under the default web site).
When I moved the website to it's own IIS site, custom error pages are now being displayed!
If anyone knowns the reason why having an Application in IIS prevents custom error pages from being displayed, please add a comment here. It would be good to understand why this occurs.
I hope this helps somebody out. Had me going for quite a while.
How are you browsing IIS? If you're doing it from the same machine, then you aren't going to see your custom error pages, because the customErrors section will default to using RemoteOnly if not specified.
the problem is with the path in web.config(path="/Error/NotFound"). the url path of NotFound page will be changed when you move your website under the Default Web Site. So, give the correct url of the page at path then it will work(this is worked for me).

Is it possible to rewrite url using ColdFusion?

I have got a requirement for generating user friendly urls.I am on IIS.
My dynamic URLs looks like,
www.testsite.com/blog/article.cfm?articleid=4432
Client wants the urls should look like
www.testsite.com/blog/article_title
I know this can be easily done using IIS URL rewiter 2.0.
But the Client wants to do it using ColdFusion only. Basic idea he given like,
User will hit the url www.testsite.com/blog/article_title
I need to fetch the article id using the article_title in the url.
Using the ID to call the article.cfm page and load the output into cfsavecontent and then deliver that output to the browser.
But I do not think its possible at application server level. How IIS will understand our user friendly urls . OR am I missing something important? Is it possible to do it using ColdFusion at application server level?
First, I hate to recommend reinventing the wheel. Webservers do this and do this well.
Cold Fusion can do something like this with #cgi.path_info#. You can jump through some hoops as Adam Tuttle explains here: Can I have 'friendly' url's without a URL rewriter in IIS?.
Option #2: My Favorite: OnMissingTemplate..
Only available to users of Application.cfc (I'm pretty sure .cfm has no counterpart to onMissingTemplate).
You can use this function within application.cfc and all affected pages will throw any "missing" urls at this event. You can then place
<cffunction name="onMissingTemplate">
<cfargument name="targetPage" type="string" required=true/>
<!--- Use a try block to catch errors. --->
<cftry>
<cfset local.pagename = listlast(cgi.script_name,"/")>
<cfswitch expression="#listfirst(cgi.script_name,"/")#">
<cfcase value="blog">
<cfinclude template="mt_blog.cfm">
<cfreturn true />
</cfcase>
</cfswitch>
<cfreturn false />
<!--- If no match, return false to pass back to default handler. --->
<cfcatch>
<!--- Do some error logging here --->
<cfreturn false />
</cfcatch>
</cftry>
</cffunction>
mt_blog.cfm can have contents like, if your url is say just like /blog/How-to-train-your-flea-circus.cfm
<!--- get everything after the slash and before the dot --->
<cfset pagename = listfirst(listlast(cgi.script_name,"/"),".")>
<!--- you may probably cache queries blog posts --->
<cfquery name="getblogpost">
select bBody,bTitle,bID
from Blog
where urlname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#pagename#">
</cfquery>
<!--- This assumes you will have a field, ex: urlname, that has a url-friendly format to match
to. The trouble is that titles are generically, in most blogs, changing every special char
to - or _, so it's difficult to change them back for this sort of comparison, so an add'l
db field is probably best. It also makes it a little easier to make sure no two blogs have
identical (after url-safe-conversion) titles. --->
...
Or if you use a url like /blog/173_How-to-train-your-flea-circus.cfm (where 173 is a post ID)
<!--- get everything after the slash and before the dot --->
<cfset pageID = listfirst(listlast(cgi.script_name,"/"),"_")>
<!--- you may probably cache queries blog posts --->
<cfquery name="getblogpost">
select bBody,bTitle,bID
from Blog
where bID = <cfqueryparam cfsqltype="cf_sql_integer" value="#pageID#">
</cfquery.
...
I don't recommend using a missing file handler (or CF's onMissingTemplate). Otherwise IIS will return a 404 status code and your page will not be indexed by search engines.
What you need to do is identify a unique prefix pattern you want to use and create a web.config rewrite rule. Example: I sometimes use "/detail_"+id for product detail pages.
You don't need to retain a physical "/blog" sub-directory if you don't want to. Add the following rewrite rule to the web.config file in the web root to accept anything after /blog/ in the URL and interpret it as /?blogtitle=[everythingAfterBlog]. (I've added an additional clause in case you want to continue to support /blog/article.cfm links.)
<rules>
<rule name="Blog" patternSyntax="ECMAScript" stopProcessing="true">
<match url="blog/(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{SCRIPT_FILENAME}" matchType="IsFile" negate="true" />
<add input="{PATH_INFO}" pattern="^.*(blog/article.cfm).*$" negate="true" />
</conditions>
<action type="Rewrite" url="/?blogtitle={R:1}" appendQueryString="true" />
</rule>
</rules>
I recommend using a "301 Redirect" to the new SEO-friendly URL. I also advise using dashes (-) between word fragments and ensure that the character case is consistent (ie, lowercase) or you could get penalized for "duplicate content".
To add to what cfqueryparam suggested, this post on Using ColdFusion to Handle 404 errors shows how to replace the web server's 404 handler with a CFM script - giving you full rewrite capabilities. It is for an older version of IIS, but you should be able to find the proper settings in the IIS version you are using.
As Adam and other's have said (and the same point is made in the post) this is not something you should do if you can avoid it. Web servers working at the HTTP level are much better equipped to do this efficiently. When you rely on CF to do it you are intentionally catching errors that are thrown in order to get the behavior you want. That's expensive and unnecessary. Typically the issue with most clients or stakeholders is a simple lack of understanding or familiarity with technology like url rewriting. See if you can bend them a little. Good luck! :)

Weird 404 error in ASP.NET MVC when including "con"

I'm going through some of the crawl errors on an MVC application I maintain, and found a 404 error for a URL that looked like it should be valid.
The URL is of the format: /gifts/{categoryName}/{productName}/{productId}/
For some reason, when the productName is set to the value "con" I just get a 404 error. Any other value (different or same length of string) and it seems to work fine.
Has anyone ever seen anything like this before?
con is a reserved word and therefore cannot be put in an MVC route
You need to add the following to your web.config:
<configuration>
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
<!-- ... your other settings ... -->
</system.web>
</configuration>
See this article for more information:
Putting the Con (COM1, LPT1, NUL, etc.) Back in your URLs

Resources