Skip to content

Custom controller response

Alexanderius edited this page Dec 22, 2019 · 3 revisions

Custom controller response

You can create your custom controller response by deriving from ControllerResponse base class and implementing Process method.

Recommended asynchronous example

public class MyControllerResponse : ControllerResponse
{
    public override async Task<ControllerResponseResult> Process()
    {
        // Do your response action
        /// await ....

        return ControllerResponseResult.Default;
    }
}

Synchronous example

public class MyControllerResponse : ControllerResponse
{
    public override Task<ControllerResponseResult> Process()
    {
        // Do your response action

        return Task.FromResult(ControllerResponseResult.Default);
    }
}
  • When a controller will return your controller response then Process method will be called by framework after controller execution,;
  • ControllerResponse has the same properties like Controller base class to access Simplify.Web modules like DataCollector or WebContext, you can use them to do your actions;
  • Additional module available to controller response is ResponseWriter, this module provides writing to HTTP response;
  • Process method should return one of ControllerResponseResult enum types:
    • Default - default result, framework will process other controllers and generate a page;
    • RawOutput - indicates what subsequent controllers execution and page generation should be stopped (for example, if you are providing some custom output to client), no output data will be sent to client except your custom writing to response;
    • Redirect - indicates what controller response doing some client redirection, technically same as RawOutput.

<< Previous page Next page >>

Clone this wiki locally