November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
You can create a new IEndpointRoutingExtension and then regsiter in Statup
internal class ContentApiEndpointRoutingExtension : IEndpointRoutingExtension
{
private readonly Action<IEndpointConventionBuilder> _policyBuilder;
public ContentApiEndpointRoutingExtension(Action<IEndpointConventionBuilder> policyBuilder = null)
{
_policyBuilder = policyBuilder;
}
public void MapEndpoints(IEndpointRouteBuilder endpointRouteBuilder)
{
var conventionBuilder = endpointRouteBuilder.MapControllers();
_policyBuilder?.Invoke(conventionBuilder);
}
}
services.AddEndpointRoutingExtension<ContentApiEndpointRoutingExtension>();
Thanks for the attempt, but that did no difference at all.
Do anyone else have any idea why the CMS fails to map a route from my content item to my controller with a TemplateDescriptor for it?
I managed to work around it somewhat, and it actually made understanding how my content was routed much easier then all these archaic interface implementations, attributes, and mysterious extension methods:
I found talks about this interface in another thread: EPiServer.Core.Routing.IContentUrlGeneratorEvents
I attached to this in my app startup class like so:
app.ApplicationServices.GetInstance<IContentUrlGeneratorEvents>().GeneratedUrl += GenerateAssetPreviewUrl;
Then my method that modifies the URL looks like so:
private static void GenerateAssetPreviewUrl(object sender, UrlGeneratorEventArgs e)
{
if((e.Context.ContextMode == ContextMode.Preview || e.Context.ContextMode == ContextMode.Edit) && AssetContentMapping.IsAsset(e.Context.ContentLink)) {
e.Context.Url = new EPiServer.UrlBuilder("/assets/preview/" + e.Context.ContentLink);
}
}
Now my asset preview/edit links in epi all look like so: /assets/preview/[contentlink]/?epieditmode=True, and all I need is a controller with attributes [Route("asset")] and an action method with [Route("preview/{assetLink}")] and [Authorize(Roles = "CmsEditors,CmsAdmins")] to prevent anonymous access.
Only thing thats not working is the download link from the options dropdown in the edit interface, but I can live without that. The URL it generates is the correct view mode url, but I suspect there is a header added with ContextMode.Edit when clicking that link that causes it to 404.
Hi,
So I have a custom content provider that serves media of various kinds. This content provider is read only so its capabilities are "None". I have registered a custom content route like so:
Next I have a controller for the view of the file like so:
These above things work just fine, I can render my content as I want to using content areas and whatnot. If i enter the url of an asset it also get downloaded like it should, great!
Now, for the problem: I want to have a custom edit mode preview for this content, where it shows editors some metadata I have on the content. If I do nothing, I get a "preview is not available...", and I can donwload the file if I open the options menu and click "Download this file".
Now, I do as suggested and add a preview controller for this content type like so:
When I add the above controller, and click the "view" option from the asset pane hamburger menu for my content, I get a 404 for the content, also the "download this file" link stops working as it also 404s. I have tried various action methods as can be seen above, but If I attach a debugger, not even the "OnActionExecuting" method gets called. So simply adding the above controller will break the /EPiServer/CMS/Content/... URL for my content. I assume any call to my content with contextmode set to "edit" will break. Note: The "view" mode things still work just fine as before.
In my cms 11 project, there was this route registered, which worked (built before my time so cant say anything else about it), but the routing extensions is not avialable in CMS 12 anymore:
I am suspecting that something is trying to route to the controller and fails to find the method it needs, but I dont know how to find out what method signature I need to add.
Any ideas?