I've also created a content page to 'accept' the link called 'verify-email' using the above view as a default template.
However, whenever this URL is requested, although the verification works and the property is checked successfully on the member, the page returns an error saying:
Child actions are not allowed to perform redirect actions
The surface controller which deals with this is:
public ActionResult RenderVerifyEmail(string verifyGUID)
{
//Auto binds and gets guid from the querystring
Member findMember = Member.GetAllAsList().SingleOrDefault(x => x.getProperty("emailVerifyGUID").Value.ToString() == verifyGUID);
//Ensure we find a member with the verifyGUID
if (findMember != null)
{
//We got the member, so let's update the verify email checkbox
findMember.getProperty("hasVerifiedEmail").Value = true;
//Save the member
findMember.Save();
}
else
{
//Couldn't find them - most likely invalid GUID
return Redirect("/");
}
//Just in case...
return Redirect("/");
}
Can anyone suggest how I can resolve this, and either show a message or redirect to a node on successful or unsuccessful verification?
I've tried a few things here such as replacing the problematic redirects with things like return CurrentUmbracoPage(); but seem to get errors regardless.
One thing that has worked, which I'm not sure is the best way to do things, is creating two new partial views and calling those instead of any kind of redirect. i.e:
The limitation is within MVC itself and since you are possibly already rendering other views, MVC will not allow you to perform a redirect from within a partial view. I have found that setting up your surface controller like so gets around the issue...
[ChildActionOnly]
public ActionResult VerifyEmail()
{
return PartialView("VerifyEmail", new ExampleModel());
}
[NotChildAction]
[HttpPost]
public ActionResult VerifyEmail(ExampleModel model)
{
if (ModelState.IsValid)
{
//Redirect as ModelState is valid
return RedirectToUmbracoPage(id);
}
//form submission is not valid, just return the current umbraco page without redirecting,
//this will preserve the ViewData which includes the ModelState for validation
return CurrentUmbracoPage();
}
The ChildActionOnly and NonChildAction attributes are important here.
ChildActionOnly tells us that this is not a normal route to be accessed via a URL and can only be rendered as a child action.
NonChildAction tells us that this is not to be treated as a child action, which allows us to use the same name for our action methods GET and POST, something which I would consider to be an MVC guideline (yet Umbraco just tells us to use different names and it'll work ok, I don't like this)
Surface Controller error: Child actions are not allowed to perform redirect actions.
Hi,
Rather than writing my own membership system with email verification/reset etc I'm using Warren Buckley's Standard Umbraco Membership system.
The member registration kind of works, but I'm having issues with the verification email link. The link in the email looks like this:
http://localhost:51434/verify-email?verifyGUID=7a902fa8-8511-4aeb-b804-e65d9331219a
I've created a view which contains the following code:
I've also created a content page to 'accept' the link called 'verify-email' using the above view as a default template.
However, whenever this URL is requested, although the verification works and the property is checked successfully on the member, the page returns an error saying:
The surface controller which deals with this is:
Can anyone suggest how I can resolve this, and either show a message or redirect to a node on successful or unsuccessful verification?
Many thanks.
I've tried a few things here such as replacing the problematic redirects with things like
return CurrentUmbracoPage();
but seem to get errors regardless.One thing that has worked, which I'm not sure is the best way to do things, is creating two new partial views and calling those instead of any kind of redirect. i.e:
...and:
...to provide suitable messages to the member.
Hi Dan,
The limitation is within MVC itself and since you are possibly already rendering other views, MVC will not allow you to perform a redirect from within a partial view. I have found that setting up your surface controller like so gets around the issue...
The ChildActionOnly and NonChildAction attributes are important here.
For more detail on this, go here: http://our.umbraco.org/documentation/Reference/Mvc/forms/turorial-child-action
Obviously, add in any of your business logic around this basic example.
Thanks Thom, very useful.
is working on a reply...