Redirect service side to an external url after command execution

Answers

2025/10/06 1:47 PM

Something that would be Kentico specific, highly unlikely. However, you could look at these two different types of approaches. These approaches assume you want to execute the same code for both examples.

  1. Assume you have a content type and for simplicity sake you define a few button fields: ButtonText, RedirectURL. In your, view for the content type, you can output a <form> element and place a <inout type="hidden"> element and a <button> element inside it. Your <input type="hidden"> element would look something like this: <input type="hidden" name="redirectUrl" value="@RedirectURL" />

    Your button element would look something like this:
    <button asp-controller="YourControllerName" asp-action="YourActionName" type="submit">@ButtonText</button>
    In your YourControllerName/YourActionName controller action, perform the work you want to do before redirecting to the external URL which is provided in the <input type="hidden"> value. Or it can be hardcoded (not recommended) if you wish.
  2. You can take the same approach for a widget. The overall process is the same but you have to register a widget to place on a page.

If you want to be more dynamic about it, then you could provide more input properties for the end user to provide input for.

2025/10/06 7:59 PM

after a command execution

Are you asking about redirects in the administration UI or in a website channel?

2025/10/08 7:44 AM
Accepted answer

Thanks for the unintentional rubber ducking :)

I was completely stuck in the Xperience UI page commands bubble. What I needed was a simple API controller that I could call with a custom layout template.

import React, { useState } from "react";
import {LinkButton} from "@kentico/xperience-admin-components";

interface CustomLayoutProps {
  readonly apiEndpoint: string;
}
export const CustomLayoutTemplate = ({ apiEndpoint } : CustomLayoutProps) => {
    
 return (
    <div>
         
        <LinkButton label="Call endpoint" href={apiEndpoint} />
        
    </div>
  );
};

The api controller endpoint can be secured using Secure custom endpoints

To response this discussion, you have to login first.