I have a private function like this in my controller.
private UserDetails GetUserDetails(int userid)
{
...
if (some condition check is false)
Redirect("some other page in a different subdomain");
return userDetails;
}
If the condition fails, Redirect statement is executed, but the execution doesn't stop. userDetails is returned to the calling function. There is no redirect to some other page.
How can I force the redirect?
Redirect returns a result - you're meant to use it from within an Action method as follows:
public ActionResult MyAction()
{
if (check is false)
{
return Redirect("other url");
}
// this code won't get executed after redirect
}
It looks like you should return null from the function you posted above, then check for null and return Redirect("...") if GetUserDetails returned null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With