Add ASP.NET Razor Pages route convention to all razor pages in a folder with validation - asp.net

I would like to have a way to specify a route convention applied to all pages inside a specific folder along with route data parameter validation.
For example, if I have a folder Pages/Movie with Actors and Financials pages inside it. Then what I would like is to access pages Actors and Financials pages inside Movie folder using following URLs:
~/{movieName}/Actors
~/{movieName}/Financials
Additional to that, it would be great to be able to:
If {movieName} does not exist show Not Found page of some sort.
If movie with {movieName} exists, then create Movie class and if possible using dependency injection access it is inside my pages cshtml file same way DB context can be accessed.
Ideally it would be great to be able to expand it further using ~/{movieName}/Actors/{actorName}/Bio and so on.

Related

How to Read the Tridion Page URL from the publication using Core Services?

I have a list of Tridion page URL's in an excel sheet, which should be unpublished on Click of a button for which I am developing a custom page. How do I read the URL from the publication.? For example, the URL looks like "https://www.example.com/us/en/abc/cde/index.html" (us/en - country/language; abc- folder in structure group, cde- subfolder in abc, index.html is the page) Now index.html should be unpublished.
If I understand you correctly, you have the URL of a page and you want to find the corresponding page in Tridion. First the bad news: The core service (the CM API) does not support a 'find by url'. The quick and dirty approach would be to use the CD API to retrieve the page. This will give you Page back which has an ID property. You can then use the core service to unpublish the page.
You can also do it with a pure core service approach but it's a bit more work and it's slow. It goes like this:
Start from the top level directory (in your example 'us')
List all structure groups inside the root using a filter like this:
var filter = new OrganizationalItemItemsFilterData()
{
ItemTypes = new ItemType[] { ItemType.Page },
IncludePathColumn = true
};
Use Linq to find the one with the top-level directory you're after
Move to the next directory and repeat with the child structure group you found

IIS with VBNet Aspx, how to setup/config a site (programmatically or not) to have a folder

I have IIS, using Aspx with VBNet.
I have a site ex. mystockmarketeg.com
I have many pages of the assets of the market, e.g. I use the ? and cod=THEASSET to change the page I want to display e.g.:
mystockmarketeg.com?myinsidepage.aspx?cod=ASSET1
mystockmarketeg.com?myinsidepage.aspx?cod=ASSET2
mystockmarketeg.com?myinsidepage.aspx?cod=ASSET3
Just changing the cod parameter I can access different pages.
But I think this doesn't perform very well on google.
So I want to have a url like this:
mystockmarketeg.com/ASSET1
mystockmarketeg.com/ASSET2
mystockmarketeg.com/ASSET3
Is there a way programatically in ASPX VBNEt or changing some property on ISS to do it without the need to create folders and putting the index page on each folder?
Configure ASP.NET Routing to achieve this result. Note that if you have hyperlinks with dynamic URLs, the URLs should be generated using <%$RouteUrl:...parameters...%>.
See also a detailed ASP.NET Routing description.

Plone setuphandler- In a setuphandler, how can I programatically add/create a folderish content type at root of Plonesite?

I have have made a folderish content type called supplier_folder, which displays a list of suppliers that can be added under it, and their information. I can add it through the navigation bar, but I would like to add it programatically during setup.
I have been following the tutorial on custom installer code (http://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py) and have looked at creating objects programatically (http://docs.plone.org/develop/plone/content/creating.html).
Unfortunately, the second article says I need to have a folder created. How can I get around this and add the supplier_folder object at the Plone Site outside of a folder?
IIRC, only users with role Manager or Site Administrator can add content to the root of the site; you can overcome this limitation in two ways:
by using the _constructInstance method as it bypasses the permissions when creating an item
by switching roles inside your code with plone.api.env.adopt_roles
I personally prefer the second one.
you can see an example of a pretty complex setuphandlers.py in interlegis.portalmodelo.policy package.
When you create a new Plone site, it's also creating some default content types.
Look at how Plone do: https://github.com/plone/Products.CMFPlone/blob/1471828ee97a8dd84396bad4a3286be514819869/Products/CMFPlone/setuphandlers.py#L119
There are a couple of ways to achieve this. The buildin mechanism is to use GenericSetup in combination with "structure" folder as described here: http://koansys.com/tech/create-plone-initial-content-with-generic-setup
In short you need the following:
Create a folder "structure" in your Generic Setup profile (in general, under profiles/default)
Create a .objects file with the following content: "suppliers,supplier_folder"
in "structure" create a folder "suppliers" with a .properties file and content:
[DEFAULT]
title = Suppliers
description = Some usefull description text
As far as I remember this is ok for simple structures likes your. If you have complex structures with folders and sub-folders and want more specific control you probably need to write python code. I made some stuff here: https://github.com/collective/zettwerk.setup/blob/master/zettwerk/setup/structure.py
But zettwerk.setup is not yet released, but you should be able to integrate the structure.py right into your project. Than you can the handle_structure method into your setuphandlers.py and passing a structure dict like this:
handle_structure(portal, [{'id': 'suppliers', 'portal_type': 'supplier_folder'}])
The advantage of this method is, that you can also control metadata like workflow state, default page setting, portlets, local roles and some others.

the same asp.net web application with different look

I recently created a simple asp.net webapplication and hosted in a server in my company. I need the same application for several clients, and I have to change just labels and images according to the client. Something like: "www.mycompany.com/mywebapp/client1", "www.mycompany.com/mywebapp/client2", "www.mycompany.com/mywebapp/client3"
But logic and database is the same. How could I do this? Thanks.
If it's a .Net web application or a .Net website, you would use MasterPages and user controls. This would allow you to have functionality restricted to the user controls and all style/layout considerations handled in the master pages.
If you choose to use MVC you would be using layout pages for a similar purpose and partial views in place of usercontrols.
In the case in the question, each subfolder would have its own master page:
mywebapp/client1/client1.master
mywebapp/client2/client2.master
mywebapp/client3/client3.master
and the pages inside would simply have the master page definitions and inclusion of the user controls. Your user controls would then sit in a public common folder such as:
mywebapp/sharedcontrols/login.ascx
mywebapp/sharedcontrols/clientinfodisplay.ascx
We did this slightly differently. In our case the DNS names are client1.mycompany.com
All of the DNS names are pointed at the exact same "web site" under IIS. In our master page we detect the subdomain (ie: client1) and look up the internal client id for it.
Also, we have a "skins" directory which holds the custom css and images for the client. For example /Skins/34/custom.css or /Skins/34/logo.png
Back in the master page we inject the appropriate CSS file which contains the overrides necessary to meet that customers look/feel.
For example, in our default css file we might have a definition like:
#customerLogo { background-image: url('/images/default.png');
then in the customer specific css file we'll have something like:
#customerLogo { background-image: url('/skins/34/logo.png') !important;
This allows our custom file to override the default css class definitions. Further, it allows us to override just the particular elements that need it instead of having to have a full css file per client.

Customize List.aspx for One Table in ASP Dynamic Data

I have just meticulously followed MS instructions for customising a dynamic data page template for one table. Create the folder CustomPages/MyTable/List.aspx, and copy PageTemplates/List.aspx into that folder, but I now get compiler error because I have duplicated methods in both List.aspx files.
What am I doing wrong?
Just in: I found another, non-MS page that I can't find again now, but he suggested the almost obvious: to change the class name in thej 3 files of my custom list page.
I'm not sure what it says in the instructions, but you'll need to change the namespace in the two codebehind files (List.aspx.cs and List.aspx.designer.cs) and in the "inherits" reference in the .aspx file or yes, you will have duplicate methods (same namespace, same class name, same method name).
You should change the namespace to reflect the path that the custom page is in - this will help ensure it stays unique.

Resources