I'm working on a dynamic project which is adding or changing the route urls.
For example:
I want to add sub application route like AppName/{controller}/{action}/{id}
or maybe a language information like {controller}/{action}/{id}/{language}
in this scenario, I can't touch to other routes and I have to override them.
I tried to foreach RouteTable.Routes and there is no editable values for added routes.
Thanks for any help.
I found the solution.
I cast the items in the RouteTable.Routes to Route object :)
Related
So we want to create a big website with nextjs and strapi.
We sometimes have deep nested pages like
www.ourwebsite.com/onderwijs/bijbelscholen/parttime-bijbelscholen
How is this possible?
I have tried to setup dynamic routing in nextjs which is working fine, but I have a problem.
If I want dynamic routes which are all nested I need to do something like this:
I know it's ugly, I'm sorry.
so now when I go to
www.ourwebsite.com/onderwijs/bijbelscholen/parttime-bijbelscholen
I just get the latest word from the URL and take that and put that into my API to get the right data which is working fine! I configured strapi so it finds by slug and not by id. So my API URL looks like this: www.myStrapiInstalation/api/pages/parttime-bijbelschool
but when I go to
www.ourwebsite.com/onderwijs/parttime-bijbelscholen
It's also working! but that's not good! Because it needed to give me a 404 page because it doesn't exist but now it just takes the latest word and gets the data from strapi. My API URL is still this of course: www.myStrapiInstalation/api/pages/parttime-bijbelschool
So what do I need to do?
Is it just not possible to make everything hardcoded and do I need to make nested folders with real names like: 'onderwijs', 'activiteiten' etc.
Or can I make everything dynamic so that people can make nested routes in nested routes in strapi?
I feel like this is a very stupid question, but I'm really stuck here.
Next JS allows catch-all routes, which is useful for nesting pages and have this format:
pages/post/[...slug].js
In your example, the pages folder structure would be:
pages/secondNest/[...page].js
However, since you're using Strapi to fetch the content, the routes of these pages should be known in advance so that if the user navigates to an invalid page, the result should be 404.
You can set the valid routes in Next with getStaticPaths. But notice that you will also need to set up a custom controller in your Strapi application to return the content tree of your website the way that getStaticPaths expects.
That way, it's ok to use the last part of the URL to get the content.
One disavantage of using catch-all routes, though, is that you must know the base of each URL. For example, if you have the following URLs
www.example.com/onderwijs/bijbelscholen/parttime-bijbelscholen
www.example.com/activiteiten/bijbelscholen/parttime-bijbelscholen
the folder structure in pages would be:
pages/onderwijs/[...page].js
pages/activiteiten/[...page].js
The key factor here is that the paths following the base of the URL should be set statically with the help of a custom controller that returns the tree of the content.
I am having tourble creating and routing static pages from within the Sylius CMS.
I have had this working once but now just can not get it to work at all. Creating the content for the page works fine but when I try to save a route all I get is errors.
An exception has been thrown during the rendering of a template
("Parameter "id" for route "sylius_backend_static_content_update" must
match ".+" ("" given) to generate a corresponding URL.") in
SyliusWebBundle:Backend/Content/StaticContent:update.html.twig at line
20.
Image of the page I am trying to save
Any help would be appreciated as there doesn't seem to be any documentation on this part of sylius.
May be you can have a look into the link below. I also had some problems with the routes while creating the pages. I had solved it by adding some info into the database. Hope this link helps you.
https://github.com/Sylius/Sylius-Standard/issues/78
Happy Syliusing ^^
I'm having a mind shattering problem with ASP .NET routing. I can't tell if this is a bug in Microsoft code or if I'm just using it wrong.
The scenario is basically this:
I have a custom route I want to add. In addition, I'm registering ASP .NET DynamicDataRoutes. If I leave out my custom route, all the ASP .NET DynamicDataRoutes work fine. Once I add this before my DynamicDataRoute:
routes.Add(new Route("IgnoreDirectory/{*pathInfo}"), new StopRoutingHandler()));
all the DynamicHyperlinks generated by DynamicData are generated with the wrong root url, like this one:
http://localhost/IgnoreDirectory/MyTable/List
which should be (and was until I added my custom route)
http://localhost/MyDynamicData/MyTable/List
What's weird is that I'm adding my DynamicDataRoute for a COMPLETELY different path:
routes.Add(new DynamicDataRoute("MyDynamicData/{{table}}/{{action}}")
{
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = model
});
Why is adding a route for IgnoreDirectory causing my DynamicData routes to use a base url of IgnoreDirectory????
I can't figure it out.
I'm going out on a limb here, but I think it has to do with two things. The order that the routes are stored in the RouteTable are significant in that the application will use the first route it finds in order to match the URL.
What I think might be happening here is that the DynamicDataRoute is building itself upon the Route that you are inserting before the DynamicDataRoute in the route table.
The first thing I would do is try moving the Route add after the DynamicDataRoute has been added.
Hope this helps...
I keep running into problems with URLs and routing.
Couldn't find an answer on SO.
I would like to manage all of my urls/links in a single place.
This is for my C# MVC code and the js/jquery ajax code.
These urls are scattered throughout my application.
Moving to a production server needs some fixes and I don't like the fact that I need to look for all of the occurrences in the application.
I don't mind fixing this once - but I would like to do it only once.
Any ideas how to manage all of these links/urls as a group will be very appreciated.
Be happy ad enjoy life, Julian
Consider using T4MVC
You could use Html.ActionLink or
Html.BuildUrlFromExpression(c => c.ControllerAction())
Depends, if you have application reading off certain urls and those urls changed once in a while. then you might want to consider putting all those urls into a database table/etc and retrieve them using specific key.
that way, when your url changed, all you need to do is to change the url on your database and all your application will still be running fine.
Urls should be managed in a single place: the RegisterRoutes static method in Global.asax. In absolutely every other part of your application you should use Html helpers when dealing/generating urls. This way you will never have problems because helpers take into account your routing system.
So instead of writing:
$('#foo').click(function() {
$('#result').load('/mycontroller/myaction');
return false;
});
you use an HTML helper to generate this foo:
<%: Html.Action("foo", "myaction", "mycontroller") %>
and then:
$('#foo').click(function() {
$('#result').load(this.href);
return false;
});
Never hardcode a single url in your application except of course in global.asax which is the only centralized place urls should be defined. So basically every time you find yourself writing something of the form /foo/bar in some other part than global.asax you are doing it wrong.
I need to customise the title property for SiteMapNodes.
I am using WSS, and have created a custom document library. While navigating through this library I want to change the names of the nodes in the breadcrumb displayed above the list name.
So far I have:
created a class inheriting from
System.Web.SiteMapProvider,
added my class to the web.config,
changed the sharepoint
default.master page sitemappath (in
PlaceHolderTitleBreadcrumb) to point
to my new site map provider.
I then overwrote the CurrentNode property to edit the CurrentNode.title with the desired name.
My problem is all the previous nodes (parent nodes) revert back to their original names. How do I edit the breadcrumb so that all the nodes navigated through keep their new title?
Any advice or direction would be appreciated.
The way I've done this before isn't by creating a new SiteMapProvider, but by replacing the sealed SharePoint AspMenu control with MossMenu (the same as AspMenu but open sourced by the SharePoint team). I then overrode OnMenuItemDataBound with the behaviour I needed.
If you need/prefer to use SiteMapProvider, have you tried using Reflector or the new .NET Framework debugging support to see how it works? There must be somewhere in the SiteMapProvider code where your overridden changes are, in turn, also being overridden. :-)