Can't catch 404 error in Composite C1 - http-status-code-404

I've set up a multi language webapplication using Composite hostnames like it's mentioned here: http://docs.composite.net/Configuration/UrlConfiguration/Hostnames.
Now I would like to log which URL the user could not find. I am struggling to figure out how to do this. I've tried custom razor functions on my 404 page defined in Composite, but Request.UrlReferer is always null. The FileNotFoundHandler.ashx handler inside Renderers, never seems to be hit.
Any idéas?
Cheers
Jens

Try Request.RawUrl in the razor function.

Related

templatetags and context['request']

So i'm learning Wagtail and trying to understand how to generate menus. So far i've found the bakerydemo repo helpful. One major point of confusion for me is understanding how to use the templatetags used for menus in the bakery demo. Below is the code for the get_site_root tag (django docs recommend that as of 1.11 that simple_tag will also work and so I changed it to that.)
#register.assignment_tag(takes_context=True)
def get_site_root(context):
# This returns a core.Page. The main menu needs to have
# the site.root_page
#defined else will return an object attribute error ('str' object
#has no attribute 'get_children')
return context['request'].site.root_page
No matter what I do I can't seem to get this to work. Either nothing is returned or I get various errors like the request key isn't in context or others. I looked at the Site middleware then traced that to the site model staticmethod "find_for_request" which in turn should be calling "get_site_for_hostname" in the sites.py . Anyways, I would love some guidance on what I am doing wrong or misunderstanding. Also, any help in understading the "wagtailthonic" way of generating menus from page hierarchies would be welcome.
Here is an image of the page and site tables.

Usually the form is POST, but in a single instance it is GET

I do a standard pattern in my application - a link to /controller/delete/object_id, then a post form to "confirm", a check if $this->request->is('post') and if true - the controller deletes the object from database.
What is weird is that for a single, particular object_id, my browser (Firefox) forces the form to be a GET one. With any other object_id everything is ok, but with this particular one, despite all declarations within form tag and etc. brower generates a GET request.
Do you have any clue what this might be?! I even tried to use brower's private mode, because I thought it can be some garbage in browser cache, but the bug is still here.
I managed to bypass this problem:
define a specific action in form->create, pointing to your controller' method
add a hidden field with object_id
add some additional code in the controller method to get object_id from $this->request->data, because a hidden post field is not passed as an argument to method, as it is with GET method.
This way, to some unknown reason, it just works. Anyway, I still feel I'm doing something wrong. It's not as "clean" as I would expect.

Composite C1 - MVC Player conflicting with Blog module

I have a composite C1 site - working fine. Some pages use the MVC Player - which works fine - along with all pages on the site - except the Blog which causes a routing conflict.
Error: The incoming request does not match any route.
C1 Function: Composite.AspNet.MvcPlayer.Render
Error details:
Exception has been thrown by the target of an invocation.
The incoming request does not match any route.
This error appears at the top of the page - the blog works fine under the error - I just need to get rid of the cause of this error. I guess the MVC controller is trying to route the blog pages because it thinks they don't exist & can't find the controller.
How can I get the controller to ignore the blog - or fix this some other way?
Short answer is that both items (blog and mvc player) are fighting over the path portion of your URL. They both expect they own the path into bit to do routing.
Example: /en/Blog /2011/11/29/Chamonix-To-Courmayeur-Skiing-Day-Trips
The /en/Blog portion is routing you to the page hosting your blog, while the rest is path info that is passed along to any functions you may have hosted on the page. Since the path is "one thing" there is no distinction whether this string is intended for the blog function or the MVC Player function. This is what is creating the confusion.
Provided you wish to leave the blog as is you can work around this issue in two ways:
Move the feature you have in MVC Player to another function provider, like Razor Functions
Change the MVC Player so it does not pass the path info along to you MVC controller.
The second workaround can be done quick and dirty by editing ~/App_Code/Composite/AspNet/MvcPlayer/Player.cs and commenting out this line (line 57)
Path = PathInfo;
Before you do this note that this would impact all your running instances of MvcPlayer.
To create a new alternative MvcPlayer which does not rely on routing (leaving the original one intact) do this:
Copy Player.cs to NoRoutePlayer.cs (and rename the class accordingly) and make the above mentioned change there (comment out line 57).
Then register this new function in Composite C1 by going to Functions | C# Functions | Composite | AspNet | MvcPlayer and add a node here, using the existing Render element as inspiration. Just set the 'Type' name to NoRoutePlayer.
With that change you will have a Player function and a NonRoutingPlayer function and you can then use the latter to run your MVC controller, and everyone should get along just fine :)

cakephp url append invalid parameter But still work. Should be 404 page not found

I find a problem when i develop application via cakephp.
for example: my url is http://localhost/controller/view/id this is working fine.
BUT, when i append more invalid parameter, it still works,
like http://localhost/controller/view/id/adfasd/adfasdf/asdfasdf/asdfasdf
It should show up 404 page not found.
Shall i need to use $this->passedArgs to check pass parameter manually in controller then throw exception? Or is there any configuration?
How can i deal with this case
Thank you
You should first look here Cakephp, Routing-Named params to find out how to properly use them.
As you should add which one to use, you should also add a regex to your id in the route.
Also when sending the data to an action you should throw the exception there like it is explained here: cakephp deal with passing wrong parameter in url

CakePHP Routing Alias, no prefix

I have a dashboard with a series of widgets. Per specification, the widgets need to be buried under a /widgets/ directory.
So I have added the following to my routes.php
Router::connect('/widget/:controller/:action/*', array());
But I seem to be running into trouble on widget/links/ and widget/links/view/1
I am new to CakePHP, but this doesn't seem all that impressive. I have yet to find anything in the Book or by search. So any help is appreciated.
Thanks.
Well...at the risk of stating the obvious...your route starts with /widget/, but you indicate that you're trying to access it via a plural URI (/widgets/). That's a problem. If that's just a typo, it would help to know what error you're seeing when you "run into trouble".
UPDATE:
Yes that was a typo. I corrected it. The error that appears for widget/links/ is: Error: WidgetController could not be found. It appears my index/default route is the main problem.
Given that information, it appears that CakePHP thinks that widget is your controller. Cake processes routes top down and finds the first one that matches. Ensure that you don't have a route above this one that looks something like /:controller/... or any other route above this one that starts with a variable.

Resources