Skip to main content

Posts

Umbraco Forms Custom Workflows Tip: How to redirect to another page other than the default thank you page after submitting an Umbraco Forms form

Umbraco Forms  is an add-on for Umbraco CMS that allows you to easily create forms and link them to your content pages. After the form submissions, you can redirect your web users to a "thank you" page using the built-in "Submit message / Go to page" workflow. However, what if you want to redirect to a page dynamically based on the data submitted by the end user? Custom workflow to redirect  One of the best solutions is to create a custom Umbraco Forms workflow based on requirements.  For Umbraco v13+ websites, rather than using the HttpContext to redirect, which won't work out of the box for your custom workflow, you should use the WorkflowExecutionContext to set the GoToPageOnSubmit property of your form, like this. context . Form . GoToPageOnSubmit = goToPage . Id ; It is as simple as this. You can now do your tests and dynamically redirect your users to the next page after the form submissions. Full code using ProjectName . Website . Core . FormExtension...
Recent posts

How to resolve "InvalidOperationException: Cannot resolve 'ProjectName.SendEmailCustomUmbracoWorkflow' from root provider because it requires scoped service 'ProjectName.ICustomServiceName'"

When you access a custom service from within your Custom Umbraco Workflow or a similar environment, you may encounter an "Invalid Operation Exception." This error typically occurs because you are attempting to use a scoped service within a singleton context. Solution If you need to use a scoped service within a singleton, inject IServiceScopeFactory into the singleton. Then, create a scope to pull out your context when needed. using ProjectName . Microsites . Cms . DataAccess . Constants ; using ProjectName . Web . Services . Interfaces ; using Newtonsoft . Json . Linq ; using Umbraco . Forms . Core ; using Umbraco . Forms . Core . Attributes ; using Umbraco . Forms . Core . Enums ; using Umbraco . Forms . Core . Persistence . Dtos ; namespace ProjectName . Web . UI . Workflows {     public class CrmFieldMapper : WorkflowType     {         private readonly ILogger < CrmFieldMapper > _logger;         private ...

How to resolve "The access level is set to private because anonymous access is disabled on this storage account." while creating a new Azure Blob Storage container

If you want to create a new Azure Blob Storage container and see the following "Anonymous access level" restriction, below are the steps that you can follow to resolve this restriction. Problem I can not add a container due to the following access level restriction.  Solution This restriction is due to the "Allow Blob anonymous access" setting being set to Disabled. After selecting the Enabled option and saving the changes, I can add my new container with the access level setting that I want.

Solutions Architect Notes: Key Responsibilities

A Software Solutions Architect is responsible for designing and overseeing the implementation of software solutions that align with business needs and technical requirements .  Solution Architects often take on various roles depending on the projects they're involved in. However, for many of these projects, there are some key responsibilities that remain consistent. Key Responsibilities Solution Design and Architecture Define the overall structure and components of software solutions. Choose appropriate technologies, frameworks, and platforms. Ensure scalability, security, and performance in system design. Requirement Analysis Work with stakeholders to understand business needs. Translate requirements into technical specifications. Identify potential risks and constraints. Technology Selection and Integration Evaluate and recommend suitable technologies and tools.  Ensure seamless integration with existing systems and third-party services. Optimise software for future scalabi...

How to find all ModelState errors of a submitted form in ASP.NET Core MVC and Razor Pages

The ModelState class in ASP.NET encapsulates the state of model binding to a property of an action-method argument or to the argument itself, and ModelState.IsValid check is commonly used by the .NET Developers to check whether a web user has submitted a form with all of the necessary details and if they haven't, then the "check" can be used to return some validation errors.  public async Task < IActionResult > OnPostAsync () {     if ( ! ModelState . IsValid )     {         return Page ();     }     _context . Movies . Add ( Movie );     await _context . SaveChangesAsync ();     return RedirectToPage ( "./Index" ); } When you have a big form, which you shouldn't have as it is not a great experience for the end users, and if you need to check the model state errors, below is a way to do exactly that.  ModelState . Values . SelectMany ( x => x . Errors . Select ( x => x . ErrorMes...

Umbraco Tip: How to enable Umbraco redirect tracking for a specific document type

Recently, I was working on an Umbraco case with my colleague, Harry Buxton, and the issue was that even though we were updating the names of certain content pages, the links to those pages were not updated correctly. As a result, we couldn't access those pages on the front end. Furthermore, they were not visible in the "Redirect URL Management" dashboard either.  Problem Umbraco CMS has a built-in URL Redirect Management feature for routing and URL tracking. Whenever a document is published, and this causes changes to its URL (and any of its decendants' URLs), Umbraco makes a note of the old URLs and whenever an incoming request is served and the default content finders cannot find a matching published document, Umbraco checked whether the URL matches on of these saved URLs. If a match is found, Umbraco returns a "301 Redirect" response pointing to the new URL of the document.  The issue was that this was not happening with our content pages; after updating...

Umbraco Tip: How to securely fix "SurfaceController POST not allowed outside Umbraco due to missing antiforgery token"

Today, I was working on a v8 to v13 upgrade project, and I realised that I couldn't access my [HttpPost] actions in a SurfaceController from an Ajax POST call. After trying some solutions without any luck, including Route attributes to the SurfaceController and actions, I found out that starting from Umbraco v9, the SurfaceControllers have the anti-forgery check by default as SurfaceControllers are primarily made for POSTing forms within Umbraco.  To resolve this issue, I added the following  beforeSend bit to my Ajax call and also added the [ValidateAntiForgeryToken] attribute to my actions in my SurfaceController. During tests, I also realised that I could ignore the anti-forgery token completely by adding the [IgnoreAntiforgeryToken] attribute to my actions, but this is not an option that anybody should go for as this option skips the anti-forgery token validation and makes your website more vulnerable for things like Cross-site request forgery attacks.   $ . ajax...