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

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

Related

Rebuilt My .ASPX Website But How to Easily Redirect to .NET Core Pages [on Shared Hosting]?

I know this has been asked before but I haven't seen any simple explanations and I should also add I'm on shared hosting (Plesk). I don't see the URLRewriter utility installed on the server.
Anyway, I rebuilt my 2013 website that did use ASP.NET web forms (with .ASPX extensions). I'd like to be able to redirect my old pages to their new equivalents. i.e.
https://www.findaforum.net/diyfishkeepers-com.aspx
Should now point to:
https://www.findaforum.net/Forums/diyfishkeepers-com/
At the moment the .ASPX pages show this in a red box on a yellow screen:
XML Parsing Error: no element found
Location: https://www.findaforum.net/diyfishkeepers-com.aspx
Line Number 1, Column 1:
Where does this "come" from?
Incidentally, I'm looking for a quick and easy fix because I don't have too many external links pointing to my site's subpages, but it would be nicer for the user experience to fix it while Google works out I've changed my entire site.
This answer basically works:
How to redirect .ASPX pages to .NET Core Razor page
There's a good link to the URL rewriting regular expressions here: https://isitoktocode.com/post/introduction-to-url-rewriting-using-iis-url-rewrite-module-and-regular-expressions
This is what I've put in Startup.cs:
var options = new RewriteOptions()
.AddRedirect(#"ShowCategories.aspx", "/Home/Categories/")
.AddRedirect(#"Statistics.aspx", "/Home/TopForums/")
.AddRedirect(#"SubmitForum.aspx", "/Home/Submit/")
.AddRedirect(#"Help.aspx", "/Home/HelpAndFAQ/")
.AddRedirect(#"([0-9a-z-A-Z]+)(.aspx)", "/Forums/$1/");
app.UseRewriter(options);
Note: Make sure you put the specific ones at the top, then the generic ones at the bottom.
I also had some URLs like https://www.findaforum.net/lpsg-com where 'lpsg-com' is a forum name. I added a URL to the home controller to take care of these...
[HttpGet]
[Route("{code}")]
public ActionResult Unknown(string code)
{
return RedirectToAction(code, "Forums");
}

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

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.

Getting URL of published element in SDL Tridion

Is there any way of finding the absolute URL for a published object in the SDL Tridion Interface?
For example when I published a page, how can I find the url where to access the page?
Though not finished, and not really very documented, the Tridion 2011 PowerTools includes 2 buttons to "Open in Staging" and "Open in Live".
If you're looking for the code in your c# tbb library you can use the PublishLocationUrl property for pages and structure groups:
StructureGroup.PublishLocationUrl or
Page.PublishLocationUrl
This will return the URL if the item is published or not, as Page and StructureGroup extend the ReposityObject class, I typically perform a check to see if the ReposityObject is published to the target that the Page is being published to for example:
if (PublishEngine.IsPublished(myReposityObject, myEngine.PublishingContext.PublicationTarget))
{
// page or sg is published!
}
Note: Where the myEngine is an instance of the Engine object.
If you're doing this in the core service, that's a little different, what you need to do is create a PublishLocationInfo object which is casted from your Page or StructureGroup object property LocationInfo, as shown below:
PublishLocationInfo pubInfo = (PublishLocationInfo)page.LocationInfo;
return pubInfo.PublishLocationUrl;
It is not very straightforward, mostly because Tridion allows you to publish a single page to multiple targets (= web sites). The page could in fact have a number of URLs.
However, the best option is to open the page and click on the Info tab. There you will find the File Path, which might look like this: \about\press\2011. Replace the backslashes with slashes, and add the page's filename and file extension (can be found on the General tab). Put the whole thing behind the root URL of your web site (e.g. http://www.mysite.com').
Tridion exposes the path of the URL in PublishLocationUrl property. You can access this either through the TOM.NET API or by viewing the raw XML of the item by entering the TCMURI in the address bar of Internet Explorer (e.g. tcm:4-264-64).
But in either case those will just return the path part of the URL. You'll have to prefix it with the correct base URL as Quirijn already mentioned earlier.
In the past, I have resorted to extending the protocol schemas for publication target destinations. Having added a baseURL property there, I could access this from events system code (the idea was to mail a link to a workflow approver).
These days, you could use application data to do the same thing.

ASP.NET MVC 3, IIS7, 404 Error, not routing correctly?

I'm newish to ASP.NET MVC 3, so sorry if I'm my details are slightly murky. I'm trying to publish my web app to a server here. I'm running in IIS 7, set to integrated, and I can get to the home page of the app just fine. However, certain links remove the directory out of the url. Example:
URL of home page:
http://localhost/CMS/ - this will take you to the first screen, with links to "Contract," "Customer," and "Employee." Clicking one of those brings you to...
http://localhost/CMS/Contract (or whichever you choose.) From there, it's broken down into different categories. One of them is "Create Contract." Here's the problem I'm having: that URL points to
http://localhost/Contract/Create - completely omitting the CMS part out and throwing a 404. I can reach it by inserting CMS back inside, and those pages route correctly.
What could be wrong? Let me know if you need more information on any of my code or whatever.
You can define an alternate controller in the route than what you would expect
routes.MapRoute("Contract", "Contract/{action}",
new { controller = "cms", action = "index" }
);
and you should be constructing your links like this within your pages
<%=Html.ActionLink("Contract", "create", "cms") %>
rather than doing it the old fashioned way like
Contracts
which side steps routing.
It sounds like you don't need additional routes but need to create ActionLinks propery using the HtmlHelper
When you are using your paths to to the controller actions you need to use #Url.Action("action", "controller"); instead of just using "action\controller".
See an example http://codetuner.blogspot.com/2011/07/jquery-post-url-problems-in-iis-hosted.html

How do you dynamically rename a node in a ASP.NET sitemap?

On our site, we have our sitemap in this order:
SiteName > SelectedProject > Path > To > Page
Where SiteName takes you to the very root page which is primarily to select a project and SelectedProject takes you to the project's homepage.
Currently, in the Web.sitemap file, SelectedProject has a static name. How can I rename it to the name of the selected project, which can be obtained from Session("PRJ")?
I'd strongly prefer any code behind to be given in VB.NET, not C#. Thanks a lot in advance!
first is you site map coming from the database or is it fully static???
if you want it to make it dynamic you have to make a new table and store all your data there!!
but if that file is static then i think you can use this code:
theNameOfYourSitemapControl.selectedNode.Text ="thenameoftheproject"

Resources