Getting URL of published element in SDL Tridion - 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.

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

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");
}

How edit code template ASP MVC 4 CRUD Generator?

I want to alter the default code genaration of MVC CRUD ASP . NET.
Visual Studio.It generates pages of "Edit.cshtml/Insert.cshtml/Delete.cshtml"
I want to translate "Edit" to "Alterar" - "Insert" to "Inserir", and I would like that the razor file to be called "Alterar.cshtml" instead of "Edit.cshtml"
How can I do that?
Is it possible?
Yes, you can.
Based on this excellent blogpost by Scott Hanselman I changed the default template in a few steps. The difference between Scott's approach and mine is that he apparently made it in a way that keeps the global default but gives him a separate generator for each project. Since I didn't get it working immediately, I opted to instead just change the global template.
Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController (some parts of the URI may vary in your situation
Optionally: grant yourselves write privileges on Controller.tt
Open Controller.tt in an editor of your choice and change what you want to change. Note that these are T4 templates so you have a wide variety of tools to your disposition if you want to do more advanced stuff.
Create a new ASP.NET MVC project
Go to the "Controllers" folder and add a new controller (not an api controller)
You don't have to change anything to get a differently named view: the view, including the file in which it is stored, is generated based on the name of the action method that creates it. If you generate the view from Alterar then the popup window will present you with the name "Alterar" for the file.

How can we save multimedia components using external resource types if the URL doesn’t end in with a file extension?

We have a Tridion use case related to curated content where we are creating multimedia components for images associated with our content which are pointing to External resource types instead of uploaded resource types.
One of the issues we have run into with this use case is that despite explicitly setting the Multimedia Type for the resource, if the URL of the image has either a query string in it: http://cdn.hw.net/UploadService/1c8b7f28-bb12-4e02-b888-388fdff5836e.jpg?w=160&h=120&mode=crop&404=default or uses a ‘friendly url’: http://www.somewhere.com/images/myimage/ when we save the component, Tridion barfs with error messages similar to : ‘Invalid value for property 'Filename'. Unexpected file extension: jpg?w=160&h=120&mode=crop&404=default. Expecting: jpg,jpeg,jpe.’
So far, the only way we’ve been able to figure out to potentially get around this issue is to do something hacky like appending an extra query string parameter to the very end of the urls which end with the expected file extension: http://cdn.hw.net/UploadService/1c8b7f28-bb12-4e02-b888-388fdff5836e.jpg?w=160&h=120&mode=crop&404=default&ext=.jpg Obviously, this is not the best solution and in fact may not work for some images if the site they are being served from strictly validates the requested URL.
Does anyone have any ideas on how we can work around this issue?
Unfortunately I can't really think of an easy solution to this, since Tridion "detects" the Mime type by checking the file extension.
You could perhaps add it while saving and remove it when reading (via Event System)? Definitely a worthwhile enhancement request, to my knowledge this behavior has not been changed for the soon-coming Tridion 2013... See comment below, it has been changed for 2013.
+1 for Nuno's answer. Recognizing that the title of your question is specific to multimedia components, you may want to consider another approach which is to use normal Components, not Multimedia Components. You can create a normal component schema called something like "External Image" that has an External Url field to store your extentionless url.
Content authors will then include these images via regular component linking mechanisms in the Tridion GUI.
You will then need a custom link resolver TBB that will parse the Output item (via Regex) looking for any Tridion anchor tags <a tridion:href="tcm:x-y-z"> and for each one replace them with an <img src=...> tag where the src path would come from this linked component.
For an example of a similar approach, but with videos, and sample code for a custom link resolver TBB have a look at the code in the following post: http://www.tridiondeveloper.com/integration-sdl-tridion-jw-media-player.

Export ASPX to HTML

We're building a CMS. The site will be built and managed by the users in aspx pages, but we would like to create a static site of HTML's.
The way we're doing it now is with code I found here that overloads the Render method in the Aspx Page and writes the HTML string to a file. This works fine for a single page, but the thing with our CMS is that we want to automatically create a few HTML pages for a site right from the start, even before the creator has edited anything in the system.
Does anyone know of any way to do this?
I seem to have found the solution for my problemby using the Server.Ecxcute method.
I found an article that demonstared the use of it:
TextWriter textWriter = new StringWriter();
Server.Execute("myOtherPage.aspx", textWriter);
Then I do a few maniulatons on the textWriter, and insert it into an html file. Et voila! It works!
Calling the Render method is still pretty simple. Just create an instance of your page, create a stub WebContext along with the WebRequest object, and call the Render method of the page. You are then free to do whatever you want with the results.
Alternatively, write a little curl or wget script to download and store whichever pages you want to make static.
You could use wget (a command line tool) to recursively query each page and save them to html files. It would update all necessary links in the resulting html to reference .html files instead of .aspx. This way, you can code all your site as if you were using server-generated pages (easier to test), and then convert it to static pages.
If you need static HTML for performance reasons only, my preference would be to use ASP.Net output caching.
I recommend you do this a very simple way and don't do it in code. It will allow your CMS code to do what the CMS code should do and will keep it as simple as possible.
Use a product such as HTTrack. It calls itself a "website copier". It crawls a site and creates html output. It is fast and free. You can just have it run at whatever frequency you think is best.
It decouples your HTML output needs from your CMS design and implementation. It reduces complexity and gives you some flexibility in how you output the HTML without introducing failure points in your CMS code.
#ckarras: I would rather not use an external tool, because I want the HTML pages to be created programmatically and not manually.
#jttraino: I don't have a time interval in which the site needs to be outputted- the uotput has to occur when a user creates a new site.
#Frank Krueger: I don't really understand how to create an instance of my page using WebContext and WebRequest.
I searched for "wget" in searchdotnet, and got to a post about a .net class called WebClient. It seems to do what I want if I use the DownloadString() method - gets a string from a specific url. The problem is that because our CMS needs to be logged in to, when the method tries to reach the page it's thrown to the login page, and therefore returns the login.aspx HTML...
Any thoughts as to how I can continue from here?

Resources