Redirect user from custom actor to dynamically generated URL



We would like to have a custom actor which dynamically generates a URL which we want browser to redirect user to after posting. How would we go about achieving this?

In this documentation I only find the following information: 

Actors must return an object instance of a class which implements EPiServer.Forms.Core.PostSubmissionActor.Internal.ISubmissionActorResult.
By implementing this interface, the returned result will have two properties:

  • CancelSubmit (boolean): determines whether the form submission should be canceled or not.
  • ErrorMessage (string): this error message will be displayed to visitors.
Nov 06, 2018 14:01

Hi mh,

If you only want to dynamically generate an URL and then redirect user to that URL you just need to override BuildReturnResultForSubmitAction method of DataSubmissionService class. The example below will redirect browswer to google site after submission. 

// Dependency

context.Services.AddTransient<DataSubmissionService, CustomDatasubmissionService>();
public class CustomDatasubmissionService : DataSubmissionService
    protected override SubmitActionResult BuildReturnResultForSubmitAction(bool isJavaScriptSupport, bool isSuccess,
                                            string message, HttpContextBase httpContext, FormContainerBlock formContainer = null, Dictionary<string, object> additionalParams = null,
                                            SubmissionInfo submissionInfo = null, Submission submission = null, bool isProgressiveSubmit = false, string redirectUrl = "")
        var baseResult = base.BuildReturnResultForSubmitAction(isJavaScriptSupport, isSuccess, message, httpContext, formContainer, additionalParams, submissionInfo, submission, isProgressiveSubmit, redirectUrl);
        if (isSuccess) // only set redirect url when sucesss
          // generate your own URL
          baseResult.RedirectUrl = "";

        return baseResult;
Edited, Nov 07, 2018 7:59

ISubmissionActorResult and ISyncOrderedSubmissionActor are available from Forms version 4.16. There may be several actors (both built-in and custom actors) will be run along with submission process. ActorsExecutingService is responsible for triggering all actors while submitting form.

1. Actors implementing ISyncOrderedSubmissionActor interface will be run first. If there are many instanace of this interface, they will be run in ascending order. SaveDataToStorageActor is one built-in actor implement this interface. SaveDataToStorageActor is responsible for saving data to storage and it has Order = 1000. So if you want to have another actor run before saving data to storage, that actor should implement ISyncOrderedSubmissionActor and set Order < 1000

2. Asynchronous actors (actors with IsSyncedWithSubmissionProcess is set to false) will be run (e.g built-in actor CallWebhookAfterSubmissionActor & SendEmailAfterSubmissionActor)

3. Synchronous actors (actors with IsSyncedWithSubmissionProcess is set to true) will be run. 

Edited, Nov 07, 2018 8:18

Thanks for your reply, I will try this.

Nov 07, 2018 12:59

why would you register service explicitly in service collection and at the same time use ServiceConfiguration attribute?

Nov 07, 2018 13:50

hi Valdis,

Yes you're right, no need to use ServiceConfiguration attribute. I Edited the code.

Nov 08, 2018 2:29
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.